ModuleNotFoundError:我的Django项目中没有名为'newsletter.model'的模块

时间:2017-11-13 02:12:40

标签: python django django-models django-forms

我开始了这个Django项目。创建了一个名为newsletter的应用程序。

这是我的models.py:

from django.db import models

# Create your models here.
class SignUp(models.Model):
    email = models.EmailField()
    full_name = models.CharField(max_length=120, blank=False, null=True)
    timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
    updated = models.DateTimeField(auto_now_add=False, auto_now=True)

    def __str__(self):
        return self.email

这是我的admin.py:

from django.contrib import admin

# Register your models here.
from .forms import SignUpForm
from .models import SignUp


class SignUpAdmin(admin.ModelAdmin):
    list_display = ["__str__", "timestamp", "updated"]
    form = SignUpForm
    #class Meta:
     #   model = SignUp

admin.site.register(SignUp, SignUpAdmin)

然后我打开了forms.py:

from django import forms

from .model import SignUp

class SignUpForm(forms.ModelForm):
    class Meta:
        model = SignUp
        fields = ['email']

问题是,当我试图运行server时,它给了我错误:

File "C:\Users\JOSHUA\Documents\trydjango18\src\newsletter\admin.py", line 4, in <module>
    from .forms import SignUpForm
  File "C:\Users\JOSHUA\Documents\trydjango18\src\newsletter\forms.py", line 3, in <module>
    from .model import SignUp
ModuleNotFoundError: No module named 'newsletter.model'

有人请帮忙。

1 个答案:

答案 0 :(得分:0)

你的forms.py中有拼写错误。尝试:

from .models import SignUp