Reputation: 13
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)
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$
Upvotes: 0
Views: 456
Reputation: 422
Other than the typo in "moldels" pointed out by FBSO, there is also another in the same line in "form", it should be "from":
from appTwo.models import User
Upvotes: 2
Reputation: 5466
You misspelled models:
form appTwo.moldels import User
to
form appTwo.models import User
Upvotes: 2