0

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.

6
  • did you check your browser's console for any 404 ? Commented Nov 9, 2014 at 22:07
  • yes, no 404 error. here you can see the result: kleedkamerscherm.nl/dsvd Commented Nov 9, 2014 at 22:16
  • 5
    Your question indicates that, contrary to your title, the URL is working properly, but the CSS and images are not. Which makes this a question about static files, which has been asked hundreds of times here before. Commented Nov 9, 2014 at 22:34
  • Although the problem does not lie with the urls.py file it should still be noted that the urls.py file is malformed Commented Nov 9, 2014 at 22:53
  • Are you developing on a live server? That's a bold move. Commented Nov 9, 2014 at 22:53

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.