Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django 404 error-page not found

My project is named homefood, and when I runserver I get this error.Anybody have any clue how to fix this error.

Page not found (404)

Request Method: GET

Request URL:    http://127.0.0.1:8000/

Using the URLconf defined in homefood.urls, Django tried these URL patterns, in this order:

^foodPosts/

^admin/

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.

My settings.py file looks like this...

import dj_database_url
"""
Django settings for homefood project.

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
STATIC_ROOT = 'staticfiles'


# SECURITY WARNING: keep the secret key used in production secret!


# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

TEMPLATE_DIRS = (

    os.path.join(BASE_DIR, 'templates'),
)


 TEMPLATE_DEBUG = True

ALLOWED_HOSTS = ['*']       # Allow all host headers


# Application definition

INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
'django.contrib.sites',
'foodPosts',
'registration',
'profiles',
'homefood',

)

MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'homefood.urls'

WSGI_APPLICATION = 'homefood.wsgi.application'



#=  dj_database_url.config()
#'default': dj_database_url.config(default='mysql://localhost')}
DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': 'django_db',
    'USER': 'root',
    'PASSWORD': '',
    'HOST': '',
    'PORT': '',
}
}#= dj_database_url.config()

# Honor the 'X-Forwarded-Proto' header for request.is_secure()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'America/New_York'

USE_I18N = True

USE_L10N = True

USE_TZ = True

#Django-registration additions, for account registration
ACCOUNT_ACTIVATION_DAYS=7
EMAIL_HOST = 'localhost'
EMAIL_PORT = 102
EMAIL_HOST_USERNAME = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_USE_TLS = False
DEFAULT_FROM_EMAIL = '[email protected]'

STATIC_URL = '/static/'


STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),

)                                           #static asset configuration

and my urls.py in my homefood folder is

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




from django.contrib import admin
admin.autodiscover()

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


  url(r'^foodPosts/',include('foodPosts.urls')),
  url(r'^admin/', include(admin.site.urls)),


 )

I think my problem is either in my urls.py, or my settings.py but I am unsure. Any help would be greatly appreciated. Thanks.

like image 667
user3014093 Avatar asked Nov 20 '13 17:11

user3014093


People also ask

How do I fix Django error page not found?

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. Let's do that by turning off Django debug mode. For this, we need to update the settings.py file.

Why do we get 404 error?

404 error codes are generated when a user attempts to access a webpage that does not exist, has been moved, or has a dead or broken link. The 404 error code is one of the most frequent errors a web user encounters. Servers are required to respond to client requests, such as when a user attempts to visit a webpage.

What is Django w3schools?

What is Django? Django is a Python framework that makes it easier to create web sites using Python. Django takes care of the difficult stuff so that you can concentrate on building your web applications.


1 Answers

You are getting the 404 because you haven't defined a url pattern for http://127.0.0.1:8000/ yet.

You should be able to view the admin site at http://127.0.0.1:8000/admin/ and your food posts at http://127.0.0.1:8000/foodPosts/.

To add a url pattern for the homepage, uncomment the following entry in your urls.py, and replace homefood.views.home with the path to the view you want to use.

url(r'^$', 'homefood.views.home', name='home'),
like image 84
Alasdair Avatar answered Sep 21 '22 13:09

Alasdair