django-vue-template icon indicating copy to clipboard operation
django-vue-template copied to clipboard

What's the point of the index view?

Open wooooodward opened this issue 6 years ago • 1 comments
trafficstars

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'),

wooooodward avatar Oct 04 '19 14:10 wooooodward

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.

CodeSpent avatar Oct 16 '19 14:10 CodeSpent