我希望我的django应用程序中有虚荣心url,即用户配置文件在url上,比如example.com/username。我试着这么做,就像这样:
urlpatterns = patterns('',
#sitemap generation
url(r'^sitemap\.xml$', sitemap, {'sitemaps': sitemaps},name='django.contrib.sitemaps.views.sitemap'),
url(r'^grappelli/', include('grappelli.urls')), # grappelli URLS
url(r'^admin/', include(admin.site.urls)),
..other urls
#User Profile URLs
url(r'^(?i)(?P<username>[a-zA-Z0-9.-_]+)$','myapp.views.user_profile',name='user-profile'),
)由于用于虚空的url模式最终出现在urlpatterns中,因此django应该在最后匹配它。但是,尽管它与管理url和user_profile视图冲突,但是呈现'example.com/ admin‘url而不是默认。确保虚荣心url不与任何django-url冲突的最佳方法是什么?是否需要编写regex,以便排除django应用程序的现有urls集。
发布于 2015-08-01 10:27:25
您的中间件将/admin/重定向到/admin。这与管理员的regex不匹配,只与您的用户配置文件匹配。使用此中间件,您无法到达管理索引页。
一种解决方案是,只有在旧路径(带有斜杠的路径)无效且新路径有效时才重定向。
https://stackoverflow.com/questions/31759409
复制相似问题