ModuleNotFoundError:没有名为的模块(projectname.appname)

2024-09-27 23:17:30 发布

您现在位置:Python中文网/ 问答频道 /正文

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']

管理员

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')

url.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主线程中出现异常:

文件“C:\Users\Dhiraj Subedi\Desktop\Dhiraj\crudproject1\crudproject1\url.py”,第18行,在 从注册导入视图 文件“C:\Users\Dhiraj Subedi\Desktop\Dhiraj\crudproject1\enroll\views.py”,第1行,在 从crudproject1.enroll.forms导入学生注册 ModuleNotFoundError:没有名为“crudproject1.enroll”的模块

我正在创建一个Django应用程序,我正面临这个问题,你能帮我吗

`


Tags: djangonamefrompyimportadminmodelsrequest
1条回答
网友
1楼 · 发布于 2024-09-27 23:17:30

您可以从同一应用程序的forms模块导入StudentRegistation(可能应该重命名为StudentRegistration)。因此,您可以通过以下方式导入此文件:

from enroll.forms import StudentRegistation

或与之相关的:

from .forms import StudentRegistation

相关问题 更多 >

    热门问题