You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Django中Reverse for 'profileEditor'无参数错误求助

Django反向解析错误解决方法

你的问题核心是URL配置要求传入pk参数,但模板调用时未提供:

  • 你的urls.py中profileEditor的路径定义包含<int:pk>,意味着反向解析这个URL必须传入一个整数类型的主键参数
  • 模板里的{% url 'profileEditor' %}没有传参,导致Django找不到匹配的URL

直接修改模板中的URL调用即可,分两种场景:

  • 如果是跳转当前登录用户的资料编辑页:
    {% url 'profileEditor' user.pk %}
    
  • 如果是跳转其他用户的资料编辑页(比如管理员操作):
    假设你在循环用户列表,变量为target_user:
    {% url 'profileEditor' target_user.pk %}
    

额外检查editProfilePage类的配置,确保它符合UpdateView的要求:

  • 必须指定model属性(比如model = User),让Django知道要编辑的模型
  • 设置fields属性,指定允许编辑的字段(比如fields = ['username', 'email', 'avatar'])
  • 可选设置success_url,指定编辑完成后的跳转路径

内容的提问来源于stack exchange,提问作者pedro echavarria

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.25 14:45:40