Django ValueError-视图没有';t返回HttpResponse对象。它没有返回任何结果

Django ValueError-视图没有';t返回HttpResponse对象。它没有返回任何结果,django,django-views,Django,Django Views,“我的视图”当前返回的错误为 视图viajecenter.views.receive\u付款未返回 HttpResponse对象。它没有返回任何结果 我在这里尝试了其他相关帖子中的一些解决方案,但没有成功 这是我的视图.py文件中的函数: def receive_payment(request, account_code): template_name = 'receive-payment.html' user = request.user account = get_object_or_4

“我的视图”当前返回的错误为

视图viajecenter.views.receive\u付款未返回 HttpResponse对象。它没有返回任何结果

我在这里尝试了其他相关帖子中的一些解决方案,但没有成功

这是我的视图.py文件中的函数:

def receive_payment(request, account_code):
template_name = 'receive-payment.html'

user = request.user

account = get_object_or_404(Account, account_code=account_code)
if user.is_assigned:
    puv = Puv.objects.get(assignment_id=user.assignment_id)
    locations = puv.route.locations.all().order_by('distance_from_base')

    context = {
        'account': account,
        'puv': puv,
        'locations': locations,
    }
    return render(request, template_name, context)

else:
    return user
from django.urls import path
from . views import ..., receive_payment


urlpatterns = [
    ...
    path('receive-payment/<str:account_code>', receive_payment, name="receive-payment"),
]
以及url.py文件中相应的url:

def receive_payment(request, account_code):
template_name = 'receive-payment.html'

user = request.user

account = get_object_or_404(Account, account_code=account_code)
if user.is_assigned:
    puv = Puv.objects.get(assignment_id=user.assignment_id)
    locations = puv.route.locations.all().order_by('distance_from_base')

    context = {
        'account': account,
        'puv': puv,
        'locations': locations,
    }
    return render(request, template_name, context)

else:
    return user
from django.urls import path
from . views import ..., receive_payment


urlpatterns = [
    ...
    path('receive-payment/<str:account_code>', receive_payment, name="receive-payment"),
]

感谢您抽出时间回答我的问题:)

您似乎在尝试混合和匹配基于函数的视图和基于类的视图

您可以像这样重写视图:

urlpatterns=[
路径('receive-payment/',ReceivePaymentView.as_view(),name=“receive payment”),
]

您似乎在尝试混合和匹配基于函数的视图和基于类的视图

您可以像这样重写视图:

urlpatterns=[
路径('receive-payment/',ReceivePaymentView.as_view(),name=“receive payment”),
]

您的代码毫无意义
get\u context\u data
只适用于基于类的视图,而不是像您的
receive\u payment
目前这样的基于函数的视图。另外,我想我在您之前的文章中已经向您解释了这一点?我的错,对不起@AbdulAzizBarkat在我的另一篇文章中纠正了我的格式。我已经编辑了我的文章,希望它更有意义:)你的代码毫无意义
get\u context\u data
只适用于基于类的视图,而不是像您的
receive\u payment
目前这样的基于函数的视图。另外,我想我在您之前的文章中已经向您解释了这一点?我的错,对不起@AbdulAzizBarkat在我的另一篇文章中纠正了我的格式。我已经编辑了我的帖子,希望它更有意义:)我已经尝试过了,它返回了[''account_code=63bb534b-042e-4ffb-8865-3de5b782d9a3'不是有效的UUID']。我忘了在我原来的帖子中指出“账户代码”是一个UUIDField。它成功了!我刚换到路里面。非常感谢。我已尝试过此操作,但它返回的['“account_code=63bb534b-042e-4ffb-8865-3de5b782d9a3”不是有效的UUID。“]。我忘了在我原来的帖子中指出“账户代码”是一个UUIDField。它成功了!我刚换到路里面。非常感谢。
urlpatterns = [
    path('receive-payment/<account_code>', ReceivePaymentView.as_view(), name="receive-payment"),
]