Allenph
Allenph

Reputation: 2015

Django reporting 404 error on simple view?

I'm just barely getting started with Python and Django.

I've created my modules, migrated, added my modules to the admin section, etc. Now, I need to create my first view. I've been following this guide (Yes the machine I'm on is running 1.6)

My views.py file in the app (setup) looks like this...

from django.shortcuts import render
from django.http import HttpResponse

def index(request):
    return HttpResponse("Setup Index")

My app'a urls.py looks like this...

from django.conf.urls import patterns, url
from setup import views

urlpatterns = patterns('',
    url(r'^$', views.index, name='index')
)

And my root urls.py looks like this...

from django.views.generic import TemplateView
from django.views.generic.base import RedirectView
from django.conf.urls import include, patterns, url
from django.contrib import admin as djangoAdmin
from admin.controller import ReportWizard
from admin.forms import reportDetailsForm, reportDataViewsForm
from setup import views
djangoAdmin.autodiscover()


urlpatterns = patterns('',
    url(r'^django-admin/', include(djangoAdmin.site.urls)),
    #New User Wizard URL
    url(r'^setup/', include('setup.urls')),
)

As far as I can tell I have followed the guide to the letter, but I am recieving a 404 error when navigating to myIP/setup.

There are no error messages on the 404 page. What is the issue?

enter image description here

Upvotes: 1

Views: 203

Answers (1)

user3850
user3850

Reputation:

For some reason your settings seem to override the default for either APPEND_SLASH or MIDDLEWARE_CLASSES.

Opening http://example.com/setup should cause a redirect to http://example.com/setup/, but somehow it doesn't for you.

Note that the latter URL is matched by your urls.py while the former is not (as should be the case).

The above should work if 'CommonMiddleWareis enabled andAPPEND_SLASHis set toTrue`.

Upvotes: 2

Related Questions