大家好我想让我的HTML工作,但似乎我没有得到什么。
我的HTML如下:
// ==UserScript==
// @name Timer Duck
// @namespace Timer Duck
// @description Simple counter
// @include https://duckduckgo.com/
// @version 1.0.0
// @grant none
// ==/UserScript==
$(document).ready(function() {
//Replace 'logo-wrap--home' with a visible counter formated '24(hours):60(minutes):60(seconds)'
});
我对链接项目的看法:(链接到网址: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%}
我的HTML不会像它应该的那样渲染。我收到以下错误:
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 })
使用shell Could not parse the remainder: '()' from 'project.team_id.members.count()'
的事情是真的
但是project.team_id.members.count() == 0
是project.team_id.members.count == 0
。
我怎样才能让它发挥作用?
答案 0 :(得分:3)
更改为:
{% if not project.team_id and project.team_id.members.count == 0 %}
和{% else %}
代替{% else project.team_id.members.count() > 0 %}
(无效)。
请注意()
电话后count
缺少。{/ p>
这就是你从HTML模板中调用count
函数的方式。事实上,任何功能,不仅仅是这一个。请在behind the scenes
中阅读点(.
)运算符在Django模板中的工作原理。