【发布时间】:2021-09-10 16:49:52
【问题描述】:
models.py
from django.db import models
class Dhiraj(models.Model):
name=models.CharField(max_length=100)
email=models.EmailField(max_length=100)
password=models.CharField(max_length=100)
forms.py
from django.forms import fields
from .models import Dhiraj
class StudentRegistation(forms.ModelForm):
class Meta:
models=Dhiraj
fields=['name','email','password']
admin.py
from django.contrib import admin
from .models import Dhiraj
@admin.register(Dhiraj)
class DhirajAdmin(admin.ModelAdmin):
list_display=('id','name','email','password')
views.py
from crudproject1.enroll.forms import StudentRegistation
from django.shortcuts import render
from .forms import StudentRegistation
def add_show(request):
if request.method=='POST':
fm=StudentRegistation(request.post)
else:
fm=StudentRegistation(request.post)
context={
'fm':fm
}
return render(request,'enroll/addandshow.html')
urls.py
from django.contrib import admin
from django.urls import path
from enroll import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.add_show, name="addandshow")
]
错误信息 线程 django-main-thread 中的异常:
文件“C:\Users\Dhiraj Subedi\Desktop\dhiraj\crudproject1\crudproject1\urls.py”,第 18 行,在 从注册导入视图 文件“C:\Users\Dhiraj Subedi\Desktop\dhiraj\crudproject1\enroll\views.py”,第 1 行,在 从 crudproject1.enroll.forms 导入 StudentRegistation ModuleNotFoundError:没有名为“crudproject1.enroll”的模块
我正在创建一个 Django 应用程序,我遇到了这个问题,请你帮忙
`
【问题讨论】:
-
请分享文件树。