Reputation: 2567
Im foraying into the world of django and following the tutorial from Tango with Django. However I keep getting a 404 page not found error when I try creating the basic view
.
I used the django-admin.py
command and created a folder named Project
. Which in turn has a folder the the same name( ill call it subProject here to avoid confusion) and the manage.py
file. The subProject has the files
1.init.py
2.settings.py
3.urls.py
4.wsgi.py
I then created an app folder in Project called rango
. Rango has the init.py, views,py, tests.py models.py and views.py
files.
i only edited the views
and the urls
file. they are as follows:
/rango/views.py
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello World")
/rango.urls.py
from django.conf.urls import patterns, url
from rango import views
urlpatterns = patterns('',
url(r'^$', views.index, name='index'))
I then edited the urls.py
in subProject
from django.conf.urls import patterns, include, url
from django.contrib import admin
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'project.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^rango/', include('rango.urls')),
)
I added the add in the setting file. However when i do python manage.py runserver
and go to the project URL it says
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/
Using the URLconf defined in project.urls, Django tried these URL patterns, in this order:
^admin/
^rango/
The current URL, , didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
Ive followed the tutorial as it is. What exactly is the problem?
Upvotes: 0
Views: 5781
Reputation: 11
I am having the same problem. I think that you need the HTML file to access it online. For example, in the Learning Log project by Eric Matthes, you had to make the HTML "topic" file in order to do localhost:8000/topic/1
Upvotes: 0
Reputation: 764
Because you haven't specified root url in your urls.py
you can access
http://127.0.0.1:8000/rango
but not http://127.0.0.1:8000/
. In order to access the root URL,
put url(r'^$', 'rango.views.index', name='index')
in urls.py
Upvotes: 3