I made a very simple django application, and just added a form (and related views, entries in urls.py etc), however I noticed no matter what URL I put in the address bar it always just redirects to the homepage.
This is my urls.py:
from django.conf.urls import url
from . import views
urlpatterns = [
url('', views.index, name='index'),
url('booking/new/', views.booking_new, name='booking_new'),
]
and my views.py:
from __future__ import unicode_literals
from django.shortcuts import render
from django.http import HttpResponse
from django.template import loader
from .forms import BookingForm
def index(request):
template = loader.get_template('/home/dave/dave/dave_site/home/templates/home/index.html')
return HttpResponse(template.render({}, request))
def booking_new(request):
form = BookingForm()
return render(request, 'home/booking_edit.html', {'form': form})
I noticed when attempting to access /home/booking/new or /booking/new that it just loads the default homepage I setup. When putting in any url, even a nonsense one, it still shows this website, and the log to the console from running runserver shows ever request as HTTP 200 successful.
I don't seem to have setup a catchall url, so not sure why this is happening.
What is the problem and how can I fix it?
Django url docs:
Django runs through each URL pattern, in order, and stops at the first one that matches the requested URL.
In url.py change first url to url(r'^$', views.index, name='index')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With