0

I have a problem with my urls.py file in Django which allows me wherever to have access on my admin interface, wherever to load the images. If somebody could have a look over it, thanks in advance !

from django.conf.urls import patterns, include, url
from django.contrib import admin
from django.conf import settings

urlpatterns = patterns('',
    (r'^admin/doc/', include('django.contrib.admindocs.urls')),
    (r'^admin/', include(admin.site.urls)),

    url(r'^admin/files/(?P<filepath>.*)$', 'my.app.admin.serv_backup_files', name='admin-file-serv'),


    (r'^(?P<restaurant_slug>[^(admin)][a-zA-B-_0-9]+)$', TemplateView.as_view(template_name=os.path.join(settings.G_DOC_ROOT, 'index.html'))),
    (r'^(?P<path>[^(admin)].*)$', 'django.views.static.serve', {'document_root': settings.G_DOC_ROOT}),
)

The problem is that with this configuration, I see on the console of the runserver, things like

"GET /img/field_bg.gif HTTP/1.1" 404

for all the images, that are supposed to be served statically.

I can remove the [^(admin)] from the last pattern and the site will be served well, except that it will try to reroute the admin interface to the static file.

Thanks in advance for helping me combining the static file, the subdomainless TemplateViewing and the admin normal access.

4

2 に答える 2

3

Pythonの正規表現はよくわかりませんが、これまでに使用した他のフレーバーでは、[^(admin)]' (' OR'a ' OR'd ' OR'm ' OR'i ' OR ' n 'または' '。文字クラス()は、フレーズではなく、単一の文字に一致します。[...]

「(admin)」と一致しないようにしようとしている場合は、次のように負の先読みを使用できます。

^(?P<restaurant_slug>(?!\(admin\))[a-zA-B-_0-9]+)$

または、「admin」と一致しないようにしようとしている可能性があります。

^(?P<restaurant_slug>(?!admin)[a-zA-B-_0-9]+)$
于 2013-01-24T13:33:52.080 に答える
0

ADMIN_STATIC_PREFIX設定とURL に追加する必要があるようです。

于 2013-01-24T12:36:29.040 に答える