DeleteView with 2 arguements post and user

做~自己de王妃 提交于 2019-12-06 20:58:29

The answer was in the templates. Adding a forloop after the "if" statement solved the issue. Doing this handles both arguments of the Url. "slug" of "post" model and "pk" of the "proof" model. Without the forloop It was almost impossible to satisfy both arguments of the URL

The correct Url thanks to "Paulo Almeida"

url (r'^proof_delete/(?P<slug>[-\w]+)/(?P<pk>\d+)/$', views.ProofDelete.as_view(), name='proof_delete') 

Below is the template

{% if user in post.made.all %}
    {% for proof in user.proofmade.all %}
        <a href="{% url 'proof:proof_delete' slug=post.slug pk=proof.pk %}">
            <img src="{% static 'images/thumbs_up_RED.png' %}" height="25px">
        </a><br/>
    {% endfor %}
{% else %}
    <a href="{% url 'proof:new_proof' slug=post.slug %}">
        <img src="{% static 'images/thumbs_up_BLANK.png' %}" height="25px">
    </a><br/>
{% endif %}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!