Django Template being rendered differently for different urls -


i'm using static_url in 1 of templates , works if use 1 url , fails if use another. in both cases, exact same view being run exact same template.

template code:

<link href="{{ static_url }}css/form.css" type="text/css" rel="stylesheet" /> <!-- rest of page... --> 

view code:

def myform(request): if request.method == 'post': form = myform(request.post, request.files) obj = save_form(form) if obj: send_confirmation_email(obj) return redirect('done-page') else: form = myform() return render(request, 'template.html', {'form': form,}) 

urls

# site urls.py urlpatterns = patterns('', url(r'^$', 'site.app.views.myform'), url(r'^app/', include('site.app.urls'), #... ) # app urls.py urlpatterns('site.app.views', url(r'^$', 'myform'), #... ) 

the above snippet of django site. if page accessed via "mydomain.com/" (the index of site), static_url rendered , css file linked properly. if page accessed via "mydomain.com/app/" (the index of app), static_url becomes blank and, hence no css, rest of page renders properly.

i under impression if views , templates same, url should irrelevant. missing something? must change allow static_url render regardless of url used?

i find hard believe static_url "becomes blank". there's no rational reason unless offending view response cached time when static_url literally had no value. if employing view or template caching make sure delete cache, or similar restart memcached (or other). if you're in development , using runserver, restart runserver.

the other more scenario based on when , doesn't work, static_url not prefixed /, i.e. it's static/. make link css file /static/css/forms.css on homepage (as should be), /app/static/css/forms.css on other page, not correct.


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -