Django static page?

后端 未结 5 1505
迷失自我
迷失自我 2021-01-30 11:25

I want to make a static page which will be shown to the user only if he/she clicks on a link provided in one of my models. I can do this by making a Python page alone and callin

5条回答
  •  别那么骄傲
    2021-01-30 11:49

    On Django 2.2.6, loosely following David's answer, I added the path in urls.py:

    from django.views.generic import TemplateView
    
    urlpatterns = [
        .... .... ....
        path('about',
             TemplateView.as_view(template_name='path/to/about_us.html'),
             name='about'),
    

    And I needed to adjust settings.py to specify the template directory:

    TEMPLATES = [{
        ... ... ...
            'DIRS': [os.path.join(BASE_DIR, 'template')],
    

    Then I saved the actual content in template/path/to/about_us.html

提交回复
热议问题