0

Earlier I was facing problem when I refresh the page. With this Solution I manage to solve the problem. But after applying this to url pattern, image is not loading properly. If I try to open the source of image in new tab , it redirects me to index page.

When url pattern is url(r'^.*$', IndexView.as_view(), name='index'), image is not displayed but page is refreshed properly .

When url pattern is url(r'^$', IndexView.as_view(), name='index'), image is displayed but page is not refreshed properly (Page not found) error

How to solve this.

Update: 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)
2
  • seems like it is the problem with media path & the regular expression,post your urls.py for checking details Commented Dec 14, 2016 at 3:14
  • Update urls.py added Commented Dec 14, 2016 at 18:40

1 Answer 1

0

In django urls are resolved from list's 0th index, so .* has higher priority than /static/ or /media/, so change the order of urls to get static & media urls higher priority than 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 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.