谁能理解我的消息为什么总是出现两次? print("Test")
在控制台中仅出现一次,这使我更加困惑。在我的base.html中,我通过{% include "snippets/messages.html" %}
@login_required
def claim(request, organizer, event):
context = {}
user = request.user
selected_event = get_object_or_404(Event, slug=event, organizer__slug=organizer)
if request.method == 'POST':
form = ClaimRewardForm(
request.POST,
initial={
'event': selected_event,
'user': user,
},
)
if form.is_valid():
new_reward_transaction = form.save(commit=False)
new_reward_transaction.amount_paid = form.cleaned_data['reward'].price
new_reward_transaction.ambassador = user.ambassador_profile
new_reward_transaction.reward = form.cleaned_data['reward']
new_reward_transaction.save()
# Add success message
messages.add_message(
request,
messages.SUCCESS,
_("Your reward claim was send for approval. You will receive a final confirmation via email.")
)
print("TEST")
return redirect(
'ambassadors:event',
organizer=organizer,
event=event,
)
else:
# TODO Marc: How to avoid repeating myself
form = ClaimRewardForm(
initial={
'event': selected_event,
'user': request.user,
},
)
# NEXT: Check if there is any reward that can be claimed
return render(request, 'ambassadors/claim.html', {
'context': context,
'form': form,
})
base.html
<body>
{% include "partials/header.html" %}
{% include "snippets/messages.html" %}
{% block content_before %}
{% endblock %}
<main role="main" class="container py-5">
{% block content %}
{% endblock %}
</main>
答案 0 :(得分:0)
您的消息标签包含在两个相互延伸的模板中。您确定{%include“ partials / header.html”%}也没有message标签吗?