URLconf problem: why I'm geting 404 error when I should'nt?

38 views
Skip to first unread message

Anahita Hedayati-Fard

unread,
Aug 20, 2016, 10:36:00 AM8/20/16
to Django users
Hello
I'm a beginner in Django.
I'm trying to write my first URlconf but it doesn't work and it shows me 404 error just like this:















And this my code on urls.py:









And this is my code on views.py :


And I ran the python manage.py runserve too.
What is the problem here?

*Sorry for my English.







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

M Hashmi

unread,
Aug 20, 2016, 11:31:14 AM8/20/16
to django...@googlegroups.com
url('^hello/', 'views.hello').
Also if you are trying to import within an app you don't need to write "from mysite.views import hello" instead you can write "from .views import hello".









--
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/967673b8-07f4-416e-ad61-ad489c9826d2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

M Hashmi

unread,
Aug 20, 2016, 11:56:42 AM8/20/16
to django...@googlegroups.com
You can also do it like 

url('^$', 'mysite.views.hello'),
$ means it will be your default page.

Lao Zzi

unread,
Aug 23, 2016, 8:32:31 AM8/23/16
to django...@googlegroups.com

read the django tutorial first. There is good django tutorial on the official site and also there is "django girls" tutorial on the internet. Both of them is good. Django doesn't see your urlconf. See at error, django find only ^admin/ regex. Your regex is not finded, so you have to edit you urls.py file. There is so mess inside it. Write it like this:

urls.py file

from django.conf.urls import url, include

from django.contrib import admin

from . import views

urlpatterns=[

    url('r^admin/', admin.site.urls),

    url('r^hello/', views.hello),

]

 

The dot sign '.' means the current directory. You are importing views.py file from current directory, and then call hello view from it, like this views.hello.

I think, it's also possible to write "from .views import hello", and use this view just by name 'hello', without writing "view." before it, but I don't this way, because using views.hello is more logical and clear.

20.08.2016, 17:36, "Anahita Hedayati-Fard" <a.heda...@gmail.com>:

 Hello
 I'm a beginner in Django.
 I'm trying to write my first URlconf but it doesn't work and it shows me 404 error just like this:

 And this my code on urls.py:

 And this is my code on views.py :

 And I ran the python manage.py runserve too.
 What is the problem here?

 *Sorry for my English.

 --
 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...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages