【发布时间】:2020-03-12 16:43:52
【问题描述】:
我在使用 Django-cookiecutter 从应用程序渲染模板时遇到问题!
我在我的项目中使用 Django-cookiecutter,我正在尝试在我的项目中创建一个新的博客应用程序,我已经按照本教程完成了所有工作:Creating a blog part
但我被困在我试图从名为 algo_explained 的新应用程序中呈现模板的部分。
我尝试在示例项目中关注用户应用,但没有成功。
Here's the link to my project on github
这是我目前所拥有的:
应用浏览量
explain_algorithms/explain_algorithms/algo_explained/views.py
from django.shortcuts import render
from explain_algorithms.algo_explained.models import Post, Comment
from explain_algorithms.algo_explained.forms import CommentForm
#blog_index will display a list of all your posts.
def blog_index(request):
posts = Post.objects.all().order_by("-created_on")
context = {
"posts" : posts,
}
return render(request, "blog_index.html", context)
应用专用网址
explain_algorithms/explain_algorithms/algo_explained/urls.py
from django.urls import path
from . import views
app_name = "algo_explained"
urlpatterns = [
path("blog", views.blog_index, name="blog_index"),
]
主项目网址
explain_algorithms/config/urls.py
我确实有 admin 和所有其他路线,我只是想分享什么是重要的!
urlpatterns = [
path("users/", include("explain_algorithms.users.urls", namespace="users")),
path("accounts/", include("allauth.urls")),
# Your stuff: custom urls includes go here
path("algo_explained/", include("explain_algorithms.algo_explained.urls", namespace =
"algo_explained")),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
我确实在 templates/algo_explained/blog_index.html 中有模板
这是错误: enter image description here
我将不胜感激!
【问题讨论】:
标签: python django django-templates cookiecutter-django