1
votes

Can anyone help me with this issue. When I try to access I get the following error.

Request Method: GET Request URL:
Using the URLconf defined in myproject.urls, Django tried these URL patterns, in this order: ^admin/ ^myproject/$ [name='home'] 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.

urls.py

from django.conf.urls import patterns, include, url

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
# Examples:
#url(r'^$', 'myproject.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),

url(r'^admin/', include(admin.site.urls)),
url(r'^booking/$', 'booking.views.home', name ='home'),
)

views.py

from django.shortcuts import render
#..

# Create your views here.
def index(request):
    return render("Hello, guesthouse!!")

settings.py

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'booking',
)
ROOT_URLCONF = 'myproject.urls'

WSGI_APPLICATION = 'myproject.wsgi.application'

admin.py

from django.contrib import admin
from booking.models import Bookings


# Register your models here.
admin.site.register(Bookings)

Thank you, Rads

3

3 Answers

3
votes

You are getting 404 because 'home' doesn't exist in views.py or by mistake, you have named the view wrong.

below i have changed the name of view to 'home' that matches the view specified in your urls.py

views.py

from django.shortcuts import render

def home(request):
    """
      home view
    """
    return render("Hello, guesthouse!!")
1
votes

You don't appear to have a home function in booking.views.

Expanded answer: Each URL spec has a couple of parts that tell Django how to route the request. In your post you have:

url(r'^booking/$', 'booking.views.home', name ='home'),

In order for the mapping to work you need to have the function:

booking.views.home

You have three options here, the first is to implement another view function, the second is that you can rename booking.views.index to booking.views.home, and the third is that you can change the url spec to the following:

url(r'^booking/$', 'booking.views.index', name ='home'),

All three of these options assume that you have a directory structure like:

|-<project_root_dir>
|   |
|   |- <project>
|   |- booking
|   |     |- <other files>
|   |     |- views.py
0
votes

Your error is in urls.py. Your last pattern is incorrect. I think it should be

url(r'^booking/$', 'booking.views.index'),