我是Django的新手,我创建了一个项目“first pycharm”,其结构如下:
\firstpycharm
| manage.py
| views.py
+---firstpycharm
| | middleware.py
| | models.py
| | settings.py
| | urls.py
| | wsgi.py
| | __init__.py
| |
| +---__pycache__
+---app
| | models.py
| | models.pyc
| | urls.py
| | views.py
| +---migrations
| +---static
| | +---build
| | +---images
| | +---vendors
| +---templates
| | **\---app
| | | base_site.html
| | | base_site_bk.html
| | | index.html
| | | index2.html
| | | index3.html
| | | index_bk.html
| | | invoice.html
| | | level2.html
| | | login.html
| | | map.html
| | | media_gallery.html
| | | morisjs.html
| | | other_charts.html
| | | page_403.html
| | | page_404.html
| | | page_500.html
| | | plain_page.html
| | | pricing_tables.html
| | | profile.html
| | | projects.html
| | | project_detail.html
| | | sidebar.html
| | | tables.html
| | | tables_dynamic.html
| | | top_navigation.html
| | | typography.html
| | | widgets.html
| | | xx.html
| | \---report
| | audiance_overview.html**
+---static
| \---script
+---staticfiles
| \---admin
| +---css
| +---fonts
| +---img
| | \---gis
| \---js
| +---admin
| \---vendor
| +---jquery
| \---xregexp
+---templates
我的第一个pycharm应用程序名为“app”集合.py包含内容:
^{pr2}$我的问题是我可以访问app/templates/app/中的所有html文件。但当我在app/templates/app/report中创建1个文件夹作为report时,我无法访问report/audiance_概述.html. 在
请帮助我访问它们。在
谢谢, 果酱
您似乎混淆了文件路径和url,这在Django中是两个不同的东西(例如,如果您来自php世界,这就不是相同的行为)。 如果您运行的是django开发服务器,那么您将无法以这种方式访问模板。在
简而言之,您需要在
urls.py
中定义一个指向视图的url,比如在views.py
中,该视图又将调用模板。请参见https://docs.djangoproject.com/en/1.11/intro/tutorial03/以获取有关如何工作的详细示例。在一开始可能看起来很重,但这使您可以更好地控制url方案,因为它不受任何文件系统约束。在
相关问题 更多 >
编程相关推荐