Django 1.6 URL not working

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

My urls.py application

from django.conf.urls import url, patterns import views urlpatterns = patterns('', url(r'^$', views.index, name='index')) 

Urls.py project

 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 installed in settings.py , and the application is included in INSTALLED_APPS .

I get a page not found when I go to localhost:8000/app .

Now I also can’t go to localhost:8000/admin .

 RuntimeError at /admin/ maximum recursion depth exceeded 

app 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 am I doing wrong. Please, help.

+7
python django
source share
2 answers

There is nothing wrong with your URLs.

In settings:

 DEBUG = True 

Reload http://localhost:8000/app/ and send the trace to Stackoverflow.

UPDATE

I am creating a Django project and using the code you provided. This is normal. Are you sure http://localhost:8000/app/ gives 404? http://localhost:8000/ does 404, which is expected because there is no view for / .

Also the administrator works. To explore "maximum recursion", you must provide models.py and admin.py code.

Some recommendations: rename your project. appmain (for the project) and app (for the application) are confusing because they look the same, but the appmain not the more important application, but the project.

Hope this helps.

+1
source share

Worth a try:

Change your urls.py project 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')), ) 
+1
source share

All Articles