Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django 1.6 urls not working

Tags:

python

django

I am new to Django and trying to figure out how the urls work in Django.

My app's urls.py

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

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

Project urls.py

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

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',

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

APPEND_SLASH = True is set in settings.py and app is included in INSTALLED_APPS.

I get the Page Not Found when i go to localhost:8000/app.

Now i am not able to go to localhost:8000/admin also.

RuntimeError at /admin/
maximum recursion depth exceeded

app's views.py

from django.http import HttpResponse

def index(request):
    return HttpResponse("This is Hello")

Settings.py

import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))

APPEND_SLASH = True
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'bfa&y-8d4^c&6a4hqz^am^1-xce05oj6&_$n!t=$v10fka(-!w'

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

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.admin',
    'app',
)

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 = 'appmain.urls'

WSGI_APPLICATION = 'appmain.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/

STATIC_URL = '/static/'

What i am doing wrong. Please help.

like image 257
ajknzhol Avatar asked Dec 22 '13 13:12

ajknzhol


2 Answers

There is nothing wrong with your urls.

In settings:

DEBUG = True

Reload http://localhost:8000/app/ and post the traceback to Stackoverflow.

UPDATE

I build a Django project and used the code you supplied. It runs fine. Are you sure http://localhost:8000/app/ gives a 404? http://localhost:8000/ does 404, which is expected because there is no view for /.

The admin works also. To investigate the 'maximum recursion' you should supply models.py and admin.py code.

Some advice: Rename your project. appmain (for the project) and app (for the app) are confusing since they look alike, but more important appmain isn't an app but a project.

Hope it helps.

like image 158
allcaps Avatar answered Oct 19 '22 23:10

allcaps


Worth trying:

Change your project urls.py to something like this:

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

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    url(r'^admin/', include(admin.site.urls)),
    url(r'^app/', include('project.app.urls')),
)
like image 41
Ayush Avatar answered Oct 20 '22 01:10

Ayush