【问题标题】:In Django I'm trying templates folder but it is not going in templates folder在 Django 中,我正在尝试模板文件夹,但它不在模板文件夹中
【发布时间】:2019-09-22 18:28:46
【问题描述】:

我遇到以下错误

Page not found (404)
Request Method:     GET
Request URL:    http://127.0.0.1:8000/check.html

Using the URLconf defined in myproject.urls, Django tried these URL patterns, in this order:

    webapp/
    [name='index']
    check [name='check']
    admin/

The current path, check.html, didn't match any of these.

You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.

【问题讨论】:

  • 请按照教程进行。模板与 URL 没有任何关系。

标签: django templates


【解决方案1】:

您有webapp/checkadmin/ url 模式,您应该执行以下操作以使check/ 工作:

  1. 你写一个视图:
def check(request):
       return render(request, 'check.html')
  1. 您创建了一个 url 模式(您显然做到了):
from .views import check
urlpatterns = [
     path('check/', check, name = "check"),
]

记得在check之后添加斜杠(/)

现在你可以访问 http:localhost:8000/check/ 应该可以了

【讨论】:

  • 它不起作用,但我从不同的站点得到了解决方案。感谢您的努力。
  • {% url 'app_name:file_name' %}
猜你喜欢
  • 2020-03-23
  • 2013-03-02
  • 2016-11-17
  • 2015-09-22
  • 2018-10-22
  • 2014-02-17
  • 2019-01-02
  • 1970-01-01
  • 2013-09-26
相关资源
最近更新 更多