Reputation: 7412
I'm trying to include an additional urls.py inside my main urls - however it doesn't seem to be working. I've done a bunch of searching and I can't seem to figure it out
main urls.py file - the admin works fine
from django.conf.urls.defaults import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^pnasser/',include('pnasser.urls')),
(r'^admin/',include(admin.site.urls)),
(r'^',include('pnasser.urls')),
)
I then have a folder pnasser, with the file urls.py with the following:
from django.conf.urls.defaults import patterns, include, url
urlpatterns = patterns('pnasser.views',
(r'^$','index'),
(r'^login/$','login'),
(r'^signup/$','signup'),
(r'^insertaccount/$','insertaccount'),
(r'^home/$','home'),
(r'^update/(?P<accid>\d+)','update'),
(r'^history/(?P<accid>\d+)','account_history'),
(r'^logout/(?P<accid>\d+)','logout'),
)
I'm not sure if I'm maybe missing something else in the configuration. if I visit mysite.com/admin it loads the admin correctly, if I goto mysite or any other url in the views I get 404 page not found:
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order: 1. ^pnasser/ 2. ^admin/
The current URL, , didn't match any of these.
edit settings.py installed apps:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
#'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'pnasser',
)
Update 2
So, I also tried running my site via the dev server: python manage.py runserver 0.0.0.0:8000
this works. I'm assuming somewhere in my integration with apache using mod_wsgi is the problem. However, I'm not sure where the problem would be
Upvotes: 2
Views: 24762
Reputation: 1
The following works for me:
If your urls are not working correctly, you may need to add this line to location /:
fastcgi_split_path_info ^()(.*)$;
From: https://code.djangoproject.com/wiki/DjangoAndNginx
Upvotes: -1
Reputation: 7412
The problem seemed to be in the django.wsgi file - and the differences in how the standard django.wsgi file loads a python site vs how the development server loads the site. I guess it's a well known issue, that I was unaware of. Thanks everyone for the suggestions.
Alternative django.wsgi file found here: http://blog.dscpl.com.au/2010/03/improved-wsgi-script-for-use-with.html
Upvotes: 3
Reputation: 1432
Within your URL's file you can write something like the following below. += obviously allows us to add additional 'patterns' to our 'urlpatterns' variable, this also means we can wrap these in an 'if' statement.
urlpatterns = patterns('',
(r'^admin/', include(admin.site.urls)),
)
urlpatterns += patterns('',
(r'^api/', include('api.urls')),
)
if settings.SHOP_TOGGLE:
urlpatterns += patterns('',
(r'^shop/', include('shop.urls')),)
)
Upvotes: 0
Reputation: 304
The problem is that you are using an empty regex ("^"
will match anything, including an empty url) to handle an include directive. If you do that, it will always append a first slash at your request path. Considering that on your pnasser.urls does not contain a regex for "/", there is no match for a request on mysite.com.
If you want mysite.com or mysite.com/ to take you to pnasser "index" view, you need to have something like:
from django.contrib import admin
from pnasser.views import index
admin.autodiscover()
urlpatterns = patterns('',
(r'^/?$', index),
(r'^pnasser/',include('pnasser.urls')),
(r'^admin/',include(admin.site.urls)),
)
So, you have:
If this doesn't work, make sure that you have Django's CommonMiddleware installed, and make you have APPEND_SLASH = True
(it is the default, so you shouldn't need to mess with this if you don't find it in your settings.py file).
Upvotes: 1
Reputation: 1272
from django.contrib import admin,include
admin.autodiscover()
urlpatterns = patterns('',
(r'^pnasser/',include('pnasser.urls')),
(r'^admin/',include(admin.site.urls)),
(r'^',include('pnasser.urls')),
)
maybe you missed "include" in the first line
Upvotes: 1
Reputation: 20270
Using the URLconf defined in mysite.urls, Django tried these
URL patterns, in this order:
This error message should list all possible URLs, including the 'expanded' urls from your pnasser app. Since you're only getting the URLs from your main urls.py, it suggests you haven't properly enabled the pnasser
app in settings.py's INSTALLED_APPS
.
Upvotes: 0