STATIC_URL Configure करना
STATIC_URL वह web address prefix है जो आपका browser pictures और style sheets मांगने के लिए उपयोग करता है, एक street name जैसा जो mail carrier को बताता है कि किस neighborhood में deliver करना है।In this page:
# settings.py
STATIC_URL = '/static/'
STATIC_ROOT = BASE_DIR / 'staticfiles'
settings.py में STATIC_URL Set करना
STATIC_URL एक required setting है जो Django (और browser) को बताती है कि static file requests को कौन सा URL prefix उपयोग करना चाहिए।
उदाहरण: Setting STATIC_URL in settings.py
STATIC_URL is a required setting that tells Django (and the browser) what URL prefix static file requests should use.
# settings.py
STATIC_URL = 'static/'
{# Django-only code -- models.py/views.py/urls.py/settings.py
snippets, or template markup using Django template tags/variables
-- can't run standalone via Judge0 or the browser preview, since
it needs a real Django project. Only this course's pure-Python
examples (example_lang == 'python', no Django imports) are
actually runnable, so those still get the button below. #}
STATIC_URL vs STATIC_ROOT
STATIC_URL public-facing URL prefix है; STATIC_ROOT वह absolute filesystem path है जहां collectstatic production serving के लिए files copy करता है। ये अलग purposes serve करते हैं और deployment के लिए दोनों चाहिए।
STATIC_ROOT को कभी भी एक ऐसी directory के बराबर set न करें जो आप STATICFILES_DIRS में भी list करते हैं — collectstatic source files overwrite कर सकता है।उदाहरण: STATIC_URL vs STATIC_ROOT
STATIC_URL is the public-facing URL prefix; STATIC_ROOT is the absolute filesystem path collectstatic copies files into for production serving. They serve different purposes and are both needed for deployment.
# settings.py
STATIC_URL = 'static/'
STATIC_ROOT = BASE_DIR / 'staticfiles'
{# Django-only code -- models.py/views.py/urls.py/settings.py
snippets, or template markup using Django template tags/variables
-- can't run standalone via Judge0 or the browser preview, since
it needs a real Django project. Only this course's pure-Python
examples (example_lang == 'python', no Django imports) are
actually runnable, so those still get the button below. #}
STATIC_URL को सुरक्षित रूप से Reference करना
Template में directly /static/ type करने के बजाय, {% static %} उपयोग करें ताकि URL सही रहे भले ही STATIC_URL बाद में बदल जाए।
उदाहरण: Referencing STATIC_URL Safely
Rather than typing /static/ directly in a template, use {% static %} so the URL stays correct even if STATIC_URL changes later.
{% load static %}
<link rel="stylesheet" href="{% static 'myapp/style.css' %}">
{# Django-only code -- models.py/views.py/urls.py/settings.py
snippets, or template markup using Django template tags/variables
-- can't run standalone via Judge0 or the browser preview, since
it needs a real Django project. Only this course's pure-Python
examples (example_lang == 'python', no Django imports) are
actually runnable, so those still get the button below. #}
STATIC_URLको trailing slash के बिना set करना,/staticstyle.cssजैसे malformed URLs produce करते हुए।STATIC_URL(वह URL prefix जो browsers उपयोग करते हैं) कोSTATIC_ROOT(server-side folder जहांcollectstaticलिखता है) से confuse करना।- Templates के पहले से
/static/paths hardcode करने के बादSTATIC_URLबदलना बजाय{% static %}tag उपयोग करने के।
STATIC_URLवह URL prefix set करता है जो browser में static files reference करने के लिए उपयोग होता है।- यह एक trailing slash के साथ खत्म होना चाहिए, जैसे 'static/'।
STATIC_URLSTATIC_ROOTसे अलग है, जो सिर्फ deployment के दौरान उपयोग होने वाला एक filesystem path है।- Templates को
STATIC_URLको indirectly{% static %}tag के through reference करना चाहिए बजाय इसे hardcode करने के।
Chapter Quiz — Complete all 8 topics to unlock
0/8 topics done
Complete these topics first: