gumbynr
gumbynr

Reputation: 335

Page not found using Django

I have set up my project with an index.html file in the templates folder that I created and it works fine at http://example.com. When I added a welcome.html file to the templates folder and set the urls.py and views.py files, I am getting a page not found message at http://example.com/welcome.html. I have read a number of reference sites to troubleshoot but still can't get past the 404 browser page...

In urls.py:

from django.conf.urls import patterns,include, url
from django.contrib import admin
from Payments.create import views


urlpatterns = patterns('Payments.create.views',
url(r'^$', 'home', name='home'),
url(r'^/welcome.html$', 'authorization', name='authorization'),
)

In views.py:

def authorization(request):
    WPdata = request.GET.get('data')
    if WPdata and len(WPdata) > 0:
        content = {'title' : 'My First Post',
            'author' : WPdata,
            'date' : '18th September',
            'body' : ' Lorem ipsum'
        }
    else:
        content = ""

    return render(request,'welcome.html',content) 

def home(request):
    if request.method == 'POST':
        form = NameForm(request.POST)
        if form.is_valid():
            connection = http.client.HTTPSConnection('api.parse.com', 443)
            connection.connect()
            connection.request('POST', '/1/classes/TestObject', json.dumps({
            "foo": form.cleaned_data['testCode']
            }), {
                 "X-Parse-Application-Id": "xx",
                 "X-Parse-REST-API-Key": "xx",
                 "Content-Type": "application/json"
        })
        results = json.loads(connection.getresponse().read())
    else:
        form = NameForm()

    return render(request,'index.html',{})   

I'm not sure what is the difference between the setup of index.html that it works as intended and welcome.html that it doesn't... I have tried a number of different permutations for the url pattern and nothing is recognized so any help provided would be greatly appreciated!

Upvotes: 1

Views: 125

Answers (2)

Vladir Parrado Cruz
Vladir Parrado Cruz

Reputation: 2359

Use this:

url(r'^welcome.html$', 'authorization', name='authorization')

instead of:

url(r'^/welcome.html$', 'authorization', name='authorization'),

Upvotes: 1

Gocht
Gocht

Reputation: 10256

Why don't you use only welcome instead of welcome.html? Whatever, Try this:

url(r'^welcome.html$', 'authorization', name='authorization'),

Notice that I have removed the first '/'

Upvotes: 5

Related Questions