Refs #32394 -- Changed STATIC_URL/MEDIA_URL to relative paths in tests and docs where appropriate.
This commit is contained in:
parent
9d05add447
commit
50a5f8840f
|
@ -16,7 +16,7 @@ Configuring static files
|
||||||
|
|
||||||
#. In your settings file, define :setting:`STATIC_URL`, for example::
|
#. In your settings file, define :setting:`STATIC_URL`, for example::
|
||||||
|
|
||||||
STATIC_URL = '/static/'
|
STATIC_URL = 'static/'
|
||||||
|
|
||||||
#. In your templates, use the :ttag:`static` template tag to build the URL for
|
#. In your templates, use the :ttag:`static` template tag to build the URL for
|
||||||
the given relative path using the configured :setting:`STATICFILES_STORAGE`.
|
the given relative path using the configured :setting:`STATICFILES_STORAGE`.
|
||||||
|
@ -88,8 +88,8 @@ to ``True``. If you don't have ``django.contrib.staticfiles`` in
|
||||||
This is not suitable for production use! For some common deployment
|
This is not suitable for production use! For some common deployment
|
||||||
strategies, see :doc:`/howto/static-files/deployment`.
|
strategies, see :doc:`/howto/static-files/deployment`.
|
||||||
|
|
||||||
For example, if your :setting:`STATIC_URL` is defined as ``/static/``, you can do
|
For example, if your :setting:`STATIC_URL` is defined as ``static/``, you can
|
||||||
this by adding the following snippet to your urls.py::
|
do this by adding the following snippet to your urls.py::
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.conf.urls.static import static
|
from django.conf.urls.static import static
|
||||||
|
@ -101,7 +101,7 @@ this by adding the following snippet to your urls.py::
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
This helper function works only in debug mode and only if
|
This helper function works only in debug mode and only if
|
||||||
the given prefix is local (e.g. ``/static/``) and not a URL (e.g.
|
the given prefix is local (e.g. ``static/``) and not a URL (e.g.
|
||||||
``http://static.example.com/``).
|
``http://static.example.com/``).
|
||||||
|
|
||||||
Also this helper function only serves the actual :setting:`STATIC_ROOT`
|
Also this helper function only serves the actual :setting:`STATIC_ROOT`
|
||||||
|
@ -119,7 +119,7 @@ During development, you can serve user-uploaded media files from
|
||||||
This is not suitable for production use! For some common deployment
|
This is not suitable for production use! For some common deployment
|
||||||
strategies, see :doc:`/howto/static-files/deployment`.
|
strategies, see :doc:`/howto/static-files/deployment`.
|
||||||
|
|
||||||
For example, if your :setting:`MEDIA_URL` is defined as ``/media/``, you can do
|
For example, if your :setting:`MEDIA_URL` is defined as ``media/``, you can do
|
||||||
this by adding the following snippet to your :setting:`ROOT_URLCONF`::
|
this by adding the following snippet to your :setting:`ROOT_URLCONF`::
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
@ -132,7 +132,7 @@ this by adding the following snippet to your :setting:`ROOT_URLCONF`::
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
This helper function works only in debug mode and only if
|
This helper function works only in debug mode and only if
|
||||||
the given prefix is local (e.g. ``/media/``) and not a URL (e.g.
|
the given prefix is local (e.g. ``media/``) and not a URL (e.g.
|
||||||
``http://media.example.com/``).
|
``http://media.example.com/``).
|
||||||
|
|
||||||
.. _staticfiles-testing-support:
|
.. _staticfiles-testing-support:
|
||||||
|
|
|
@ -3343,7 +3343,7 @@ Default: ``None``
|
||||||
|
|
||||||
URL to use when referring to static files located in :setting:`STATIC_ROOT`.
|
URL to use when referring to static files located in :setting:`STATIC_ROOT`.
|
||||||
|
|
||||||
Example: ``"/static/"`` or ``"http://static.example.com/"``
|
Example: ``"static/"`` or ``"http://static.example.com/"``
|
||||||
|
|
||||||
If not ``None``, this will be used as the base path for
|
If not ``None``, this will be used as the base path for
|
||||||
:ref:`asset definitions<form-asset-paths>` (the ``Media`` class) and the
|
:ref:`asset definitions<form-asset-paths>` (the ``Media`` class) and the
|
||||||
|
@ -3400,7 +3400,7 @@ tuples, e.g.::
|
||||||
("downloads", "/opt/webfiles/stats"),
|
("downloads", "/opt/webfiles/stats"),
|
||||||
]
|
]
|
||||||
|
|
||||||
For example, assuming you have :setting:`STATIC_URL` set to ``'/static/'``, the
|
For example, assuming you have :setting:`STATIC_URL` set to ``'static/'``, the
|
||||||
:djadmin:`collectstatic` management command would collect the "stats" files
|
:djadmin:`collectstatic` management command would collect the "stats" files
|
||||||
in a ``'downloads'`` subdirectory of :setting:`STATIC_ROOT`.
|
in a ``'downloads'`` subdirectory of :setting:`STATIC_ROOT`.
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ built-in handling for user-uploaded files, but you can have Django serve your
|
||||||
]
|
]
|
||||||
|
|
||||||
Note, the snippet assumes your :setting:`MEDIA_URL` has a value of
|
Note, the snippet assumes your :setting:`MEDIA_URL` has a value of
|
||||||
``'/media/'``. This will call the :func:`~django.views.static.serve` view,
|
``'media/'``. This will call the :func:`~django.views.static.serve` view,
|
||||||
passing in the path from the URLconf and the (required) ``document_root``
|
passing in the path from the URLconf and the (required) ``document_root``
|
||||||
parameter.
|
parameter.
|
||||||
|
|
||||||
|
|
|
@ -97,7 +97,7 @@ class ASGITest(SimpleTestCase):
|
||||||
|
|
||||||
@modify_settings(INSTALLED_APPS={'append': 'django.contrib.staticfiles'})
|
@modify_settings(INSTALLED_APPS={'append': 'django.contrib.staticfiles'})
|
||||||
@override_settings(
|
@override_settings(
|
||||||
STATIC_URL='/static/',
|
STATIC_URL='static/',
|
||||||
STATIC_ROOT=TEST_STATIC_ROOT,
|
STATIC_ROOT=TEST_STATIC_ROOT,
|
||||||
STATICFILES_DIRS=[TEST_STATIC_ROOT],
|
STATICFILES_DIRS=[TEST_STATIC_ROOT],
|
||||||
STATICFILES_FINDERS=[
|
STATICFILES_FINDERS=[
|
||||||
|
|
|
@ -159,7 +159,7 @@ def setup(verbosity, test_labels, parallel, start_at, start_after):
|
||||||
# Redirect some settings for the duration of these tests.
|
# Redirect some settings for the duration of these tests.
|
||||||
settings.INSTALLED_APPS = ALWAYS_INSTALLED_APPS
|
settings.INSTALLED_APPS = ALWAYS_INSTALLED_APPS
|
||||||
settings.ROOT_URLCONF = 'urls'
|
settings.ROOT_URLCONF = 'urls'
|
||||||
settings.STATIC_URL = '/static/'
|
settings.STATIC_URL = 'static/'
|
||||||
settings.STATIC_ROOT = os.path.join(TMPDIR, 'static')
|
settings.STATIC_ROOT = os.path.join(TMPDIR, 'static')
|
||||||
settings.TEMPLATES = [{
|
settings.TEMPLATES = [{
|
||||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||||
|
|
|
@ -17,9 +17,9 @@ from .models import Person
|
||||||
|
|
||||||
TEST_ROOT = os.path.dirname(__file__)
|
TEST_ROOT = os.path.dirname(__file__)
|
||||||
TEST_SETTINGS = {
|
TEST_SETTINGS = {
|
||||||
'MEDIA_URL': '/media/',
|
'MEDIA_URL': 'media/',
|
||||||
'MEDIA_ROOT': os.path.join(TEST_ROOT, 'media'),
|
'MEDIA_ROOT': os.path.join(TEST_ROOT, 'media'),
|
||||||
'STATIC_URL': '/static/',
|
'STATIC_URL': 'static/',
|
||||||
'STATIC_ROOT': os.path.join(TEST_ROOT, 'static'),
|
'STATIC_ROOT': os.path.join(TEST_ROOT, 'static'),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,8 @@ from pathlib import Path
|
||||||
TEST_ROOT = os.path.dirname(__file__)
|
TEST_ROOT = os.path.dirname(__file__)
|
||||||
|
|
||||||
TEST_SETTINGS = {
|
TEST_SETTINGS = {
|
||||||
'MEDIA_URL': '/media/',
|
'MEDIA_URL': 'media/',
|
||||||
'STATIC_URL': '/static/',
|
'STATIC_URL': 'static/',
|
||||||
'MEDIA_ROOT': os.path.join(TEST_ROOT, 'project', 'site_media', 'media'),
|
'MEDIA_ROOT': os.path.join(TEST_ROOT, 'project', 'site_media', 'media'),
|
||||||
'STATIC_ROOT': os.path.join(TEST_ROOT, 'project', 'site_media', 'static'),
|
'STATIC_ROOT': os.path.join(TEST_ROOT, 'project', 'site_media', 'static'),
|
||||||
'STATICFILES_DIRS': [
|
'STATICFILES_DIRS': [
|
||||||
|
|
|
@ -13,8 +13,8 @@ from django.test import modify_settings, override_settings
|
||||||
|
|
||||||
TEST_ROOT = os.path.dirname(__file__)
|
TEST_ROOT = os.path.dirname(__file__)
|
||||||
TEST_SETTINGS = {
|
TEST_SETTINGS = {
|
||||||
'MEDIA_URL': '/media/',
|
'MEDIA_URL': 'media/',
|
||||||
'STATIC_URL': '/static/',
|
'STATIC_URL': 'static/',
|
||||||
'MEDIA_ROOT': os.path.join(TEST_ROOT, 'project', 'site_media', 'media'),
|
'MEDIA_ROOT': os.path.join(TEST_ROOT, 'project', 'site_media', 'media'),
|
||||||
'STATIC_ROOT': os.path.join(TEST_ROOT, 'project', 'site_media', 'static'),
|
'STATIC_ROOT': os.path.join(TEST_ROOT, 'project', 'site_media', 'static'),
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ from django.test import SimpleTestCase, override_settings
|
||||||
|
|
||||||
class CheckSettingsTests(SimpleTestCase):
|
class CheckSettingsTests(SimpleTestCase):
|
||||||
|
|
||||||
@override_settings(DEBUG=True, MEDIA_URL='/static/media/', STATIC_URL='/static/',)
|
@override_settings(DEBUG=True, MEDIA_URL='static/media/', STATIC_URL='static/')
|
||||||
def test_media_url_in_static_url(self):
|
def test_media_url_in_static_url(self):
|
||||||
msg = "runserver can't serve media if MEDIA_URL is within STATIC_URL."
|
msg = "runserver can't serve media if MEDIA_URL is within STATIC_URL."
|
||||||
with self.assertRaisesMessage(ImproperlyConfigured, msg):
|
with self.assertRaisesMessage(ImproperlyConfigured, msg):
|
||||||
|
|
|
@ -7,7 +7,7 @@ from django.test import SimpleTestCase, override_settings
|
||||||
from ..utils import setup
|
from ..utils import setup
|
||||||
|
|
||||||
|
|
||||||
@override_settings(INSTALLED_APPS=[], MEDIA_URL='/media/', STATIC_URL='/static/')
|
@override_settings(INSTALLED_APPS=[], MEDIA_URL='media/', STATIC_URL='static/')
|
||||||
class StaticTagTests(SimpleTestCase):
|
class StaticTagTests(SimpleTestCase):
|
||||||
libraries = {'static': 'django.templatetags.static'}
|
libraries = {'static': 'django.templatetags.static'}
|
||||||
|
|
||||||
|
|
|
@ -142,7 +142,7 @@ class StaticHelperTest(StaticTests):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
self._old_views_urlpatterns = urls.urlpatterns[:]
|
self._old_views_urlpatterns = urls.urlpatterns[:]
|
||||||
urls.urlpatterns += static('/media/', document_root=media_dir)
|
urls.urlpatterns += static('media/', document_root=media_dir)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
|
Loading…
Reference in New Issue