gtalarico / django-vue-template

Django Rest + Vue JS Template
https://django-vue-template-demo.herokuapp.com/
MIT License
1.58k stars 406 forks source link

What's the point of the index view? #40

Open wooooodward opened 4 years ago

wooooodward commented 4 years ago

As far as I can tell the index URL path doesn't do anything.

backend/api/views.py

# Serve Vue Application
index_view = never_cache(TemplateView.as_view(template_name='index.html'))

backend/urls.py

# http://localhost:8000/
path('', index_view, name='index'),
CodeSpent commented 4 years ago

This tells the template render engine to serve index.html from your configured directory.

Settings.py

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': ['dist'], # Add dist to dirs so Django looks for templates in /dist
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

So when deploying, your build script will put index.html in /dist which mounts your application & Django will see this as a template and serve it when / route is hit.