return render(request, 'importer/calendaredit.html', {'form': calendar}) return render(request, 'importer/calendaredit.html', {'form': form})django.urls.exceptions.NoReverseMatch: Reverse for 'calendaredit' with arguments '('',)' not found. 1 pattern(s) tried: ['importer\\/calendar\\/(?P<calendar_id>[0-9]+)\\/$']
class Impcalendar(models.Model):
establishment = models.ForeignKey(Establishments, on_delete=SET_NULL, null=True)
url = models.CharField(max_length=255)
comment = models.CharField(max_length=255, null=True, blank=True)
status = models.IntegerField(null=True, blank=True)
def __str__(self):
return str(self.establishment)from django import forms
import datetime
from importer.models import Impcalendar, Establishments
class ImpcalendarForm(forms.ModelForm):
class Meta:
model = Impcalendar
fields = ['id', 'url'] from django.urls import path
from importer import views
urlpatterns = [
path('', views.index, name='index'),
path('calendar/<int:calendar_id>/', views.calendaredit, name='calendaredit')
]def calendaredit(request, calendar_id): calendar = get_object_or_404(Impcalendar, pk=calendar_id)
print (calendar.url) if request.method == 'POST': form = ImpcalendarForm(request.POST, instance=calendar) if form.is_valid(): calendar.save() else: form = ImpcalendarForm(request.POST or None, instance=calendar) return render(request, 'importer/calendaredit.html', {'form': form}){% extends 'importer/base.html' %}
{% block content %}
<h1>{{ form.id }}</h1>
{% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %}
<form action="{% url 'calendaredit' form.id %}" method="post">
<div class="fieldWrapper">
{% csrf_token %}
{{ form.id }}
{{ form.url }}
</div>
<input type="submit" value="Save" />
</form>
{% endblock %}