python - Django 在错误的地址使用格式错误的 urls.py 提供错误的模板(编辑器应用程序)
问题描述
解决方案
Few things to notice is the urlpatterns :
path('', include('posts.urls')),
Because this URL is on top Django will first look here.
In the post app you also have an urls.py that looks like the following
path('', views.posts, name='posts'),
This matches you 127.0.0.1:8000/ so this will be your homepage.
In the landings template you post to :
form action="{% url 'home' %}" method="get">
The home which is a different view in a different app.
If you want to first serve the Home landing page you need to do the following
First Change the order in your urls.py like the following:
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('redactors.urls')), 1
path('', include('posts.urls')), 2
path('', include('counters.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Second
In your redactors app go to your urls.py and change ’home’ to ’’</p>
This will make sure that you always start with the home page.
The last problem you are facing is that you are missing data when you post/get to the home view.
This is because you do not give back :
context = {'posts':posts}
in the context to the render function in your home view. So the template cannot render posts that are not available.
推荐阅读
- javascript - 未定义的弹出窗口:声明了“案例”,但它的值永远不会被读取。ts(6133)
- python - 我想在 WordPress 后期编辑页面上添加一个按钮,点击后应该调用一个 python 脚本
- javascript - Node js 中的编码与使用纯 JavaScript 编码有什么不同?
- python - 如何将整数字符串与整数进行比较?
- ssl - 如果主域在另一台服务器上,则为子域生成letsencrypt ssl
- azure-data-explorer - Kusto (KQL):值 < 0 的所有列的计数
- python - 在 Pyspark 中对行执行多个条件的最佳方法
- truffle - 在 Ropsten 上部署 Truffle
- c++ - 放置 new 和 delete 运算符出现问题
- git - 使用 git 的最佳方法是让多个开发人员更新一个通用代码库?