Error 404 in django when visiting / Runserver does not return errors, although

When I syncdb and runningerver everything works correctly in Django, but when I try to visit a web page that is at http://127.0.0.1:8000/ , it returns a 404 error.

 Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/ Using the URLconf defined in MyBlog.urls, Django tried these URL patterns, in this order: ^admin/ The current URL, , didn't match any of these. 

The strange part is that when I am on /admin on the page, it works fine. I do not understand what is not working here. Any help would be awesome!

0
source share
2 answers

You need the URL on the main page. The urlpatterns variable in MyBlog.urls should have a couple of tuples, for example (r '^ $', app.views.show_homepage), where show_homepage is the function defined in views.py. For more information on the URL manager, you can read here: https://docs.djangoproject.com/en/dev/topics/http/urls/

0
source

Check out chapter 3 of Django Writing Your First Django Application .

In short, you need to specify (in urls.py ) which Django code should run for specific URLs; there are no specific URLs by default (you will see a line including admin URLs in urls.py ).

Change your urls.py to look something like

 from django.conf.urls import patterns, include, url from django.views.generic import TemplateView from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', url(r'^$', TemplateView.as_view(template_name="home.html"), ) 

(you also need to create home.html in one of the directories specified in TEMPLATE_DIRS )

0
source

All Articles