语法错误:尝试迁移时语法无效



models.py

from django.db import models
class User(models.Model):
first_name = models.CharField(max_length=128)
last_name = models.CharField(max_length=128)
email = models.EmailField(max_length=256, unique=True)

views.py

from django.shortcuts import render
form appTwo.moldels import User
# Create your views here.
def index(request):
return render(request, 'appTwo/index.html')

def users(request):
user_list = User.object.order_by('first_name')
user_dict = {'users':user_list}
return render(request, 'appTwo/users.html', context=user_dict)

Protwo/urls.py

appTwo/urls.py

from django.conf.urls import path
from appTwo import views
urlpatterns = [
path('', views.users, name='users'),
]

我尝试过迁移,但它会导致语法错误。堆栈跟踪包括如下:

File "/home/hamid/Desktop/my_django_stuff/project_two/proTwo/proTwo/urls.py", line 18, in <module>
from appTwo import views
File "/home/hamid/Desktop/my_django_stuff/project_two/proTwo/appTwo/views.py", line 2
form appTwo.moldels import User
^
SyntaxError: invalid syntax
(myDjango) hamid@hamid-PC:~/Desktop/my_django_stuff/project_two/proTwo$

你拼错了模型:

form appTwo.moldels import User

form appTwo.models import User

除了FBSO指出的"moldels"中的错别字外,在"form"中还有另一个在同一行中,它应该是"from":

from appTwo.models import User

相关内容

  • 没有找到相关文章

最新更新