Fayyaz Hussain
Fayyaz Hussain

Reputation: 121

Render dist file (of Vuejs) through Django

Trying to render vue js build (index.html) in Django its working fine but the problem is that when i give any route to that url than i get page not found from vue.

This working fine

url(r'^$', TemplateView.as_view(template_name="index.html"), name='whatever'),

And this is not, giving page not found error of vue

url(r'^website/', TemplateView.as_view(template_name="index.html"), name='whatever'),

enter image description here

Upvotes: 1

Views: 562

Answers (1)

Ali Asgher Badshah
Ali Asgher Badshah

Reputation: 851

Hi I got a solution to the problem you have to set the default route in your router to set it redirection to the specific path

code for your router.js in vue project

new Router({
  mode: 'History',
  base: '/app'
  routes: [
   {
     path: '/',
     name: 'name',
     component: ComponentName
   }
  ]
})

and also mention the same URL name in you API in Django

urlpatterns = [
  url(r'^admin/', admin.site.urls),
  url(r'^api-token-auth/', obtain_jwt_token),
  url(r'^.*$/app', views.home),
]

for more detailed conversation refer to this answer

Upvotes: 1

Related Questions