我想通过单击按钮将状态从“基本成分”更改为“成分”。 我已经创建了一个脚本,但是不断出现错误。 有人知道我该如何解决该错误?
错误:
Reverse for '<WSGIRequest: GET '/weekstaat/indienen/26'>' not found.
'<WSGIRequest: GET '/weekstaat/indienen/26'>' is not a valid view function or pattern name.
view.py
def indienen(request, id):
global Weekstaat
weekstaat = Weekstaat.objects.get(pk=id)
Weekstaat.status = 'Ingedient'
weekstaat.save()
return redirect(request, 'weekstaat/index.html')
-模型
class Weekstaat(models.Model):
id = models.AutoField(primary_key=True, null=False, blank=False)
status = models.CharField(max_length=11, choices=STATUS_CHOICES, default='Niet ingediend',)
jaar = models.ForeignKey(Jaar, default=datetime.now().year, null=False, blank=False,on_delete=models.CASCADE)
week = models.ForeignKey(Week, default=date.today().isocalendar()[1], null=False, blank=False,on_delete=models.CASCADE)
werknemer = models.ForeignKey(User, related_name='weekstaat_werknemer', null=False, blank=False, default=1,on_delete=models.CASCADE)
maandag = models.FloatField(null=True, blank=True, default=0)
dinsdag = models.FloatField(null=True, blank=True, default=0)
woensdag = models.FloatField(null=True, blank=True, default=0)
donderdag = models.FloatField(null=True, blank=True, default=0)
vrijdag = models.FloatField(null=True, blank=True, default=0)
zaterdag = models.FloatField(null=True, blank=True, default=0)
zondag = models.FloatField(null=True, blank=True, default=0)
def __str__(self):
return str(self.jaar) + ' week ' + str(self.week) + str(self.werknemer) + str(self.status)
-html
<td class="text-center">
<a href="{% url 'weekstaat-indienen' Weekstaat.id %}">
<button class="btn btn-success btn-sm" onclick="bevestigIndienen()">indienen </button>
</a>
</td>
<td class="text-center">
<button type="button" class="read-Contract btn btn-sm btn-primary" data-id="{% url 'read_Weekstaat' Weekstaat.id %}">
<span class="fa fa-eye"></span>
</button>
<button type="button" class="update-Contract btn btn-sm btn-primary" data-id="{% url 'update_Weekstaat' Weekstaat.id %}">
<span class="fa fa-pencil"></span>
</button>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p class="text-primary">U heeft nog geen Weekstaat</p>
{% endif %}
</div>
</div>
</div>
</div>
</div>
{% endblock content %}
{% block extrascripts %}
<script type="text/javascript">
function bevestigIndienen(){
if(confirm('U staat op het punt een weekstaat in te dienen. Weet u het zeker?') != true){
document.getElementById('formulierIndienen').action = '';
window.location.href = "{% url 'home' %}";
}
}
答案 0 :(得分:0)
您的意思是render
,而不是redirect
。
(但是请注意,您实际上不应该更改GET请求的状态。您的表单应该提交POST请求,然后您的视图应在处理提交后重定向到另一个URL。)