这是我的url.py:
from django.urls import path
from newsletter.views import control_newsletter, control_newsletter_list, control_newsletter_detail, control_newsletter_edit
urlpatterns = [
path('newsletter/', control_newsletter, name='control_newsletter'),
path('newsletter_list/', control_newsletter_list, name='control_newsletter_list'),
path('newsletter_detail/<int:pk>/', control_newsletter_detail, name='control_newsletter_detail'),
path('newsletter_edit/<int:pk>/', control_newsletter_edit, name='control_newsletter_edit'),]
这是我的观点.py:
def control_newsletter_edit(request, pk):
newsletter = get_object_or_404(Newsletter, pk=pk)
if request.method == 'POST':
form = NewsletterCreationForm(request.POST, instance=Newsletter)
if form.is_valid():
newsletter = form.save()
if newsletter.status == 'Published':
subject = newsletter.subject
body = newsletter.body
from_email = global_settings.EMAIL_HOST_USER
for email in newsletter.email.all():
send_mail(subject=subject, from_email=from_email, recipient_list=[email], message=body,
fail_silently=True)
messages.success(request, 'Your Changes Write Successfully.',
'alert alert-success alert-dismissible')
else:
messages.warning(request, 'SomeThing Went Wrong..',
'alert alert-warning alert-dismissible')
return redirect('control_newsletter_detail', pk=newsletter.pk)
else:
form = NewsletterCreationForm(instance=newsletter)
context = {
'form': form,
}
return render(request, 'control_panel/control_newsletter.html', context)
当我试图接近
newsletter_edit/1/
从这里开始,在我的teplate代码中:
<div class="col-sm-8">
<div class="col-sm-2">
<a href="{% url 'control_newsletter_edit' pk=newsletter.pk %}">
<button class="btn-success">Edit</button>
</a>
</div>
我面对这个错误:
ValueError at /panel/newsletter_edit/1/
The view newsletter.views.control_newsletter_edit didn't return an HttpResponse object. It returned None instead.
我一遍又一遍地检查我的url.py和views.py,但我无法找出我的问题所在。
有人知道我为什么要面对这个错误吗?
另外,我很抱歉在我的问题上写了错误。
如果你需要我的全部观点,请告诉我。