使用Django的{%url%}模板标签时,我得到了意想不到的结果。 我希望得到一个网址,如:
domain.com/create_placement/<id>
而是返回以下内容:
domain.com/organizations/<id>/%7B%%20url%20'create_placement'%20org_id=organization.id%20%%3E
template.py
...
<a href="{% url 'create_placement' organization.id %>">Create Placement</a>
...
views.py
def create_placement(request, org_id):
if request.method == "POST":
organization = Organization.objects.get(id=org_id)
## Gather post data
placement_form = PlacementForm(request.POST)
## Validate Form
if placement_form.is_valid():
## Send to database
placement_form.save()
## redirect to placement view
placement = Placement.objects.latest('id')
return redirect('individual_organization', id=placement.id)
else:
placement_form = PlacementForm(initial = { "organization" : organization})
return render(request, "admin_tracking/create_placement.html", {'placement_form': placement_form})
urls.py
url(r'^create_placement/(?P<org_id>\d+)$', views.create_placement, name="create_placement"),
答案 0 :(得分:1)
您的问题是结尾%>
{% url 'create_placement' organization.id %>
应该是
{% url 'create_placement' organization.id %}