I
I
Ilya Oskin2016-07-25 21:20:30
Django
Ilya Oskin, 2016-07-25 21:20:30

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

3 answer(s)
R
Roman Kitaev, 2016-07-25
@Oskin1

urlpatterns = static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + [
    url(r'^', views.IndexView.as_view(), name='index'),
]

M
Maxim Vasiliev, 2016-07-25
@qmax

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.

S
sim3x, 2016-07-25
@sim3x

Gotta do it like this
instead of doing nonsense
https://docs.djangoproject.com/en/1.9/topics/http/...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question