मेरे पास एक टेम्पलेट है, base.html
, जिसका उपयोग विभिन्न विचारों के लिए कई अन्य टेम्पलेट्स में किया जाता है। उनमें से प्रत्येक टेम्पलेट उचित {% extends "base.html" %}
के साथ शुरू होता है। ,,STATIC_URL आधार Django टेम्पलेट में अपरिभाषित
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}/base.css"/>
हालांकि जब यह renders मेरे टेम्पलेट के अधिकांश, STATIC_URL
का मान रिक्त है तो विशेषता केवल href="/base.css"
है, जो लोड नहीं करता है: आधार टेम्पलेट में, मैं thusly एक स्थिर स्टाइलशीट निर्दिष्ट करना चाहते हैं । परिवर्तनीय टेम्पलेट के लिए ठीक से परिभाषित किया गया है जिसे मैंने डिफ़ॉल्ट लॉगिन दृश्य, django.contrib.auth.views.login
से बंधे हैं, लेकिन मेरे अपने कस्टम विचारों के लिए, यह अपरिभाषित है।
मैं सिर्फ runserver
के साथ विकास वातावरण में काम करने की कोशिश कर रहा हूं, इसलिए सीएसएस फ़ाइल ऐप की स्थिर उपनिर्देशिका में है।
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.static',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
)
मेरे urls.py
मैं भी जोड़ लिया है::
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
#...
urlpatterns += staticfiles_urlpatterns()
कोई भी विचार क्या मैं गलत कर रहा हूँ
यहाँ मेरी settings.py
से प्रासंगिक बिट है, जो सभी चूक कर रहे हैं? जहां तक मैं यह कह सकता हूं कि the 1.3 documentation पर आधारित, विकास में ऐप-विशिष्ट स्थैतिक फ़ाइलों की सेवा के लिए आपको क्या करना है।
इससे मुझे सही दिशा में ले जाया गया। (आपके द्वारा उद्धृत अनुभाग [यहां] है (https://docs.djangoproject.com/en/dev/ref/templates/api/#subclassing-context-requestcontext)) मैं 'render_to_response' को 'context_instance = RequestContext (अनुरोध) '। – UltraNurd
अच्छा! आपकी मदद करने में प्रसन्नता;) – danihp
यदि आप Django 1.3 का उपयोग कर रहे हैं, तो आपको context_instance में मैन्युअल रूप से पास करने की आवश्यकता नहीं है। रेंडर शॉर्टकट आपके लिए ऐसा करेगा: वापसी प्रस्तुत करें (अनुरोध, 'the-template.html', {'foo': 'bar'}) – Brandon