2016-12-13 84 views
0

早些時候,當我刷新頁面時,我遇到了問題。有了這Solution我設法解決這個問題。但是將這個應用到url模式之後,圖像加載不正確。如果我嘗試在新選項卡中打開圖像源,它會將我重定向到索引頁。圖像不顯示Django + Angular

當url模式爲url(r'^.*$', IndexView.as_view(), name='index'),圖像不顯示,但頁面正確刷新。

當URL模式顯示圖像url(r'^$', IndexView.as_view(), name='index'),但網頁無法正常刷新(找不到網頁)錯誤

如何解決這個問題。

更新: urls.py

urlpatterns = [ 
url(r'^admin/', admin.site.urls), 
url(r'^api/v1/', include(router.urls)), 
url(r'^api/v1/auth/login/$', LoginView.as_view(), name='login'), 
url(r'^api/v1/auth/logout/$', LogoutView.as_view(), name='logout'), 
url(r'^api/v1/', include(accounts_router.urls)), 
url(r'^api/v1/', include(profiles_router.urls)), 
url(r'^blogs/',include('blogs.urls')), 
url(r'^account_data/',include('customauth.urls')), 
url(r'^.*$', IndexView.as_view(), name='index'), 
#url(r'^customauth/',include('customauth.urls')), 
] 
if settings.DEBUG: 
    urlpatterns+=static(settings.STATIC_URL,document_root=settings.STATIC_ROOT) 
    urlpatterns+=static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT) 
+0

好像它是媒體路徑和正則表達式的問題,發佈你的'urls.py'來檢查細節 –

+0

更新urls.py添加 –

回答

0

在Django URL將從列表中的第0指數解決,所以.*/static//media/更高的優先級,因此更改網址以獲得static & media更高的網址優先於IndexView

urlpatterns = [ 
url(r'^admin/', admin.site.urls), 
url(r'^api/v1/', include(router.urls)), 
url(r'^api/v1/auth/login/$', LoginView.as_view(), name='login'), 
url(r'^api/v1/auth/logout/$', LogoutView.as_view(), name='logout'), 
url(r'^api/v1/', include(accounts_router.urls)), 
url(r'^api/v1/', include(profiles_router.urls)), 
url(r'^blogs/',include('blogs.urls')), 
url(r'^account_data/',include('customauth.urls')), 
#url(r'^customauth/',include('customauth.urls')), rest of the urls 
] 
if settings.DEBUG:   
    # static & media urls 
    pass 
urlpatterns+= [url(r'^.*$', IndexView.as_view(), name='index'),] # accepts any urls otherthan above