Answer the question
In order to leave comments, you need to log in
How to exclude a word from a Python regular expression?
Hello! I'm making a SPA application with Django. Url Django is configured to return a single page for any request, where the front-end framework is subsequently embedded, however, because of this, Django does not want to return media files. How can I exclude the string media? in the regular expression so that the back-end returns the main page for any query other than the one that starts with the name of the media folder?
URLs.py:
from django.conf.urls import url
from django.conf import settings
from django.conf.urls.static import static
from . import views
urlpatterns = [
url(r'^', views.IndexView.as_view(), name='index'),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Answer the question
In order to leave comments, you need to log in
urlpatterns = static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + [
url(r'^', views.IndexView.as_view(), name='index'),
]
Django goes through the urls one by one and grabs the first one he comes across.
It is enough to put media_url at the beginning of the list.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question