嗨,大家好我想讓我的HTML工作,但似乎我沒有得到的東西。在HTML中渲染django標記無法正常工作
我的HTML如下:(鏈接到網址的網站:team_select)的一個項目鏈接
{% extends 'base.html' %}
{% block body %}
<div class="container">
<div class="jumbotron">
<h2>Welcome to your Project {{ project.name }} Detail page</h2>
</div>
<!-- case 1 = if there is not team created or linked -->
{% if project.team_id == None %}
<div class="invite-team">
<div class="jumbotron">
<div class="jumbo-text">
<h3>Your project has been created, It is time to link a team or create a new for your project</h3>
</div>
<div class="jumbo-button">
<a href="{% url 'website:team_select'%}" class="btn btn-default" role="button"><span class="glyphicon glyphicon-link"></span> Link an existing team</a>
<a href="{% url 'website:add_team' %}" class="btn btn-success" role="button"><span class="glyphicon glyphicon-plus"></span> Create a new team</a>
</div>
</div>
<!-- case 2 = if there is a team created but no team members -->
{% elif project.team_id and project.team_id.members.count == 0 %}
<div class="invite-teammembers">
<div class="jumbotron">
<div class="jumbo-text">
<h3>The team {{ project.team_id }} has beed created, we now need to add TeamMembers</h3>
</div>
<div class="jumbo-button">
<a href="{% url 'registration:team_register3' %}" class="btn btn-success" role="button"><span class="glyphicon glyphicon-plus"></span> Add Team Members</a>
</div>
</div>
</div>
<!-- any other situation -->
{% else %}
<h1>Youhouu</h1>
{% endif %}
</div>
</div>
{% endblock%}
我的觀點
def TeamSelect(request):
#import pdb; pdb.set_trace()
if request.method == "POST":
select_form = EditSelectTeam(request.user, request.POST)
if select_form.is_valid():
data = select_form.cleaned_data['team_choice']
obj2 = Project.objects.filter(project_hr_admin=request.user)
obj3 = obj2.latest('id')
if obj3.team_id == None:
obj3.team_id = data
obj3.save()
obj4 = obj3.team_id
obj5 = obj4.members.all()
for i in obj5:
current_site = get_current_site(request)
message = render_to_string('acc_join_email.html', {
'user': i.first_name,
'domain':current_site.domain,
})
mail_subject = 'You have been invited to SoftScores.com please LogIn to get access to the app'
to_email = i.email
email = EmailMessage(mail_subject, message, to=[to_email])
email.send()
messages.success(request, 'test')
return render(request,'project_details.html')
else:
print('this project has already a team')
else:
print('Non Valid form')
else:
select_form = EditSelectTeam(request.user)
return render(request,'link_project.html',
{'select_form':select_form })
我的HTML未呈現,就像它應該。我得到以下錯誤:
Could not parse the remainder: '()' from 'project.team_id.members.count()'
的事情是使用shell project.team_id.members.count() == 0
是真的 但project.team_id.members.count == 0
是False
。
我該如何讓它工作?
如果不是0,如果您執行'{{project.team_id.members.count}}',那麼值是多少? – qbzenker
我不確定你的問題..但值可以是任何正整數..它正在計算一個團隊中團隊成員的數量 – Ben2pop
好吧 - 你可以嘗試'{%if project.team_id.members | length == 0%}' - ['length'](https://docs.djangoproject.com/en/1.11/ref/templates/builtins/)過濾器應該負責統計'project.team_id.members中元素的數量'。 – qbzenker