我正在尝试开发我的第一个 Django 应用程序,这是我的目录树:
demo-project
|____(html)
|____(myproject)
|___db_dump.sql
|___manage.py
|___(myapp)
| |___(templates)
| |___ __init__.py
| |___ forms.py
| |___ models.py
| |___ tests.py
| |___ views.py
|
|___(myproject)
|___ __init__.py
|___ settings.py
|___ urls.py
|___ wsgi.py
这是我的models.py
from django.db import models
from django.forms import ModelForm
from myapp.forms import mwa_event_form
class mwa_user(models.Model):
unique_id = models.IntegerField()
email = models.CharField(max_length=75)
firstName = models.CharField(max_length=40)
lastName = models.CharField(max_length=40)
gender = models.CharField(max_length=30)
birthday = models.CharField(max_length=20)
fbIdUser = models.CharField(max_length=20)
os = models.CharField(max_length=30)
class Contact(models.Model):
subject = models.CharField(max_length=100)
message = models.CharField(max_length=100)
sender = models.EmailField(max_length=100)
class mwa_event_model(ModelForm):
class Meta:
model = mwa_event_form
fields = ['bfirstName', 'blastName']
和forms.py
from myapp.models import Contact
from django import forms
class ContactForm(forms.Form):
subject = forms.CharField(max_length=100)
message = forms.CharField(max_length=100)
sender = forms.EmailField(max_length=100)
class mwa_user_form(forms.Form):
unique_id = forms.IntegerField()
email = forms.CharField(max_length=75)
firstName = forms.CharField(max_length=40)
lastName = forms.CharField(max_length=40)
gender = forms.CharField(max_length=30)
birthday = forms.CharField(max_length=20)
fbIdUser = forms.CharField(max_length=20)
os = forms.CharField(max_length=30)
class mwa_event_form(forms.Form):
class Meta:
model = Contact
fields = ['bfirstName', 'blastName']
当我尝试发出命令时,python manage.py runserver
我收到以下警告:
File "/var/lib/stickshift/51e9c62e500446b4bf0000e0/approot/data/563815/myproject/myapp/models.py", line 3, in <module>
from myapp.forms import mwa_event_form
File "/var/lib/stickshift/51e9c62e500446b4bf0000e0/approot/data/563815/myproject/myapp/forms.py", line 1, in <module>
from myapp.models import Contact
ImportError: cannot import name Contact
我错过了什么?我在类似的帖子中读到这可能与循环依赖有关,但查看 Django 文档我并没有真正理解这意味着什么。这与目录文件夹结构有关吗?