0

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$
1
  • Hi and welcome to Stack Overflow. Could you please add some more information to the body of your question about what you are trying to accomplish here? Commented Nov 26, 2019 at 3:45

2 Answers 2

2

You misspelled models:

form appTwo.moldels import User

to

form appTwo.models import User
Sign up to request clarification or add additional context in comments.

1 Comment

i changed but give same erorrFile "/home/hamid/Desktop/my_django_stuff/project_two/proTwo/proTwo/urls.py", line 4, in <module> from appTwo import views File "/home/hamid/Desktop/my_django_stuff/project_two/proTwo/appTwo/views.py", line 2 form appTwo.models import User
2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.