DreeOlee
DreeOlee

Reputation: 151

Django urls.py: url doesn't work properly

I'm developing a webpage with Django. I want to add/define an url for the application.

At this moment the url (dsvd/) doen't work properly. It shows only table data but no css and background.

here is the code for the main urls.py file.

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

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'kleedkamer_overview.views.home', name='home'),
    # url(r'^blog/', include('blog.urls')),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^', include('kleedkamer_overview.urls')),
    url(r'^dsvd/', 'kleedkamer_overview.views.indeling'),
)

and here the code inside the application urls.py file

from django.conf.urls import patterns, url

from kleedkamer_overview import views

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

Is there anyone who can help me find the problem? Greetz.

Upvotes: 0

Views: 1848

Answers (1)

user3282276
user3282276

Reputation: 3804

It looks like line is giving you trouble:

url(r'^dsvd/', 'kleedkamer_overview.views.indeling')

It seems like you are trying to map this URL to kleedkamer_overview.views.indeling but the URL regrex does not end with a '$'. Urls.py files that are mapped to other apps look like this:

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

Notice the include function call and that the regrex expression r'^admin/' does not end with a $

However mapping to a specific view is a bit different and it looks like this:

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

Notice that this time, where the include() function call would go you are instead telling Django which specific view you want to use and that the site regrex is r'^$' ending with a $.

Try changing this:

url(r'^dsvd/', 'kleedkamer_overview.views.indeling')

to this:

url(r'^dsvd/$', 'kleedkamer_overview.views.indeling')

Edit: I saw your comments and while the urls.py is not the source of your problem, what I said is still valid because the urls.py was malformed. You should not even have the offending line there at all because you have already included the urls.py from kleedkamer_overview , there is no need to include it twice. It isn't DRY and it is just bad practice in general. This is why this still works despite being malformed because sites are looked for in order, in this case first it looks for /admin then / and does not reach /dsvd because it was already caught by / and your malformed url mapping is NEVER reached.

Upvotes: 2

Related Questions