Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wooooodward opened this issue Oct 4, 2019 · 1 comment
Open

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

wooooodward opened this issue Oct 4, 2019 · 1 comment

Comments

@wooooodward
Copy link

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 wooooodward changed the title What's the point of the django index view? What's the point of the index view? Oct 4, 2019
@CodeSpent
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants