【发布时间】:2021-06-02 11:37:25
【问题描述】:
我的视图当前返回错误
视图 viajecenter.views.receive_payment 没有返回 HttpResponse 对象。它返回 None 。
我在这里尝试了其他相关帖子中的一些解决方案,但没有成功。
这是我的 views.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
以及urls.py文件中对应的url:
from django.urls import path
from . views import ..., receive_payment
urlpatterns = [
...
path('receive-payment/<str:account_code>', receive_payment, name="receive-payment"),
]
和我的帐户模型:
class Account(AbstractBaseUser, PermissionsMixin):
...
account_code = models.UUIDField(default=uuid.uuid4, editable=False)
is_assigned = models.BooleanField(default=False)
感谢您抽出时间回答我的问题 :)
【问题讨论】:
-
你的代码没有意义。
get_context_data仅适用于基于类的视图,而不是像您当前的receive_payment这样的基于函数的视图。 -
另外,我想我在您之前的 question? 中向您解释了这一点?
-
我的错,对不起。 @AbdulAzizBarkat 确实在我的另一篇文章中更正了我的格式。我已经编辑了我的帖子,希望它更有意义:)
标签: django django-views