简体   繁体   中英

SyntaxError: invalid syntax when trying migrate

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

I've tried migrating but it causes a syntax error. The stack trace is included below:

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$

You misspelled models:

form appTwo.moldels import User

to

form appTwo.models import User

除了FBSO指出的“models”中的错字,“form”中的同一行还有另一个,应该是“from”:

from appTwo.models import User

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM