Django first app

74 views
Skip to first unread message

anookeen

unread,
Jan 23, 2018, 2:13:00 PM1/23/18
to Django users
Hi , I am creating django app mentioned at this link (https://docs.djangoproject.com/en/2.0/intro/tutorial02/). When I create new views and add that into urls.py , the new urls aren't recognized (such as it doesn't recognize the question_id mentioned in part 3 of the tutorial). Kindly help me out. Thanks in advance.

Gerardo Palazuelos Guerrero

unread,
Jan 23, 2018, 2:16:07 PM1/23/18
to django...@googlegroups.com
hi anooken,
maybe you want to share your code or as an screenshot cause it does not makes sense.

regards,
Gerardo.


--
Gerardo Palazuelos Guerrero


On Tue, Jan 23, 2018 at 12:10 PM, 'anookeen' via Django users <django...@googlegroups.com> wrote:
Hi , I am creating django app mentioned at this link (https://docs.djangoproject.com/en/2.0/intro/tutorial02/). When I create new views and add that into urls.py , the new urls aren't recognized (such as it doesn't recognize the question_id mentioned in part 3 of the tutorial). Kindly help me out. Thanks in advance.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/88833b3d-b56a-476b-babf-2c26cbbbe9f5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kasper Laudrup

unread,
Jan 23, 2018, 3:02:45 PM1/23/18
to django...@googlegroups.com
Hi Anokeen,
You don't provide any context, error messages or any other kind of
information that would make it possible for people to actually help you.

Please provide that, and I'm sure someone will do their best to help you.

Kind regards,

Kasper

Daniel Hepper

unread,
Jan 23, 2018, 3:30:24 PM1/23/18
to Django users
Here is a repository that follows the tutorial step by step: https://github.com/consideratecode/django-tutorial-step-by-step/

You can compare your code to what it should look like at the step where you are stuck.

Alternatively, post your code and the exact error message here, as others have suggested.

Cheers,
Daniel

anookeen

unread,
Jan 24, 2018, 12:58:49 AM1/24/18
to Django users
This is the screenshot for mysite/urls.py




This is the screenshot for mysite/polls/urls.py


This is screenshot for mysite/polls/views.py



Screenshot of error

Auto Generated Inline Image 1
Auto Generated Inline Image 2
Auto Generated Inline Image 3
Auto Generated Inline Image 4

Daniel Hepper

unread,
Jan 24, 2018, 1:37:32 AM1/24/18
to Django users
You are using the new syntax to define URLs from Django 2.0 with the old urls() method.

If you are using Django 2.0, polls/urls.py should look like this:

from django.urls import path

from . import views

urlpatterns = [
    # ex: /polls/
path('', views.index, name='index'),
    # ex: /polls/5/
path('<int:question_id>/', views.detail, name='detail'),
    # ex: /polls/5/results/
path('<int:question_id>/results/', views.results, name='results'),
    # ex: /polls/5/vote/
path('<int:question_id>/vote/', views.vote, name='vote'),
]

If you are using an earlier version of Django, it should look like this:

from django.conf.urls import url

from . import views

urlpatterns = [
    # ex: /polls/
    url(r'^$', views.index, name='index'),
    # ex: /polls/5/
    url(r'^(?P<question_id>[0-9]+)/$', views.detail, name='detail'),
    # ex: /polls/5/results/
    url(r'^(?P<question_id>[0-9]+)/results/$', views.results, name='results'),
    # ex: /polls/5/vote/
    url(r'^(?P<question_id>[0-9]+)/vote/$', views.vote, name='vote'),
]

Notice the difference? Use from django.conf.urls.url with the old regular expression syntax and django.urls.path with the new angle bracket syntax.

Cheers,
Daniel

11

anookeen

unread,
Jan 24, 2018, 1:51:06 AM1/24/18
to Django users
Yes I got it Daniel Hepper. Thank you so much for your help.
Reply all
Reply to author
Forward
0 new messages