Kin*_*ing 3 django templates django-templates
我正在尝试将一个模板包含到另一个模板中,但我现在遇到的问题是嵌入的模板不会在我尝试将其嵌入到的新模板中显示在其上渲染的内容。
个人资料应用程序中的detail.html
{% include "list.html" with instance=user.posts_created.all %}
Run Code Online (Sandbox Code Playgroud)
我的模板位于模板文件夹中。模板可见,但内容未显示在detail.html中
将根据要求提供其他代码,谢谢
帖子应用程序中的views.py
def axle(request , tag_slug=None):
results = Post.objects.all().filter(draft=False)#.filter(publish__lte=timezone.now())
#results = results.filter(user=request.user)
tag = None
if tag_slug:
tag = get_object_or_404(Tag, slug=tag_slug)
results = results.filter(tags__in=[tag])
que = request.GET.get("q")
if que:
results =results.filter(
Q(title__icontains=que)|
Q(content__icontains=que)).distinct()
paginator = Paginator(results, 4) # Show 25 contacts per page
pages ="page"
page = request.GET.get('page')
try:
query = paginator.page(page)
except PageNotAnInteger:
query = paginator.page(1)
except EmptyPage:
query = paginator.page(paginator.num_pages)
context = {
"objects": query,
"pages": pages
}
template = 'list.html'
return render(request,template,context)
Run Code Online (Sandbox Code Playgroud)
你的 中应该有这样的东西view:
def post(request):
post_list = posts_created.objects.all() # or something which you want to do.
context = {
'post_list': post_list,
}
return render(request, 'detail.html', context)
Run Code Online (Sandbox Code Playgroud)
在template:
{% include "app_name/list.html" with objects=post_list %}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8669 次 |
| 最近记录: |