添加地址报错

添加地址报错

Internal Server Error: /acc/user/address/edit/add/

Traceback (most recent call last):

  File "C:\Users\Administrator\.virtualenvs\py3.6-EAMp6_h3\lib\site-packages\django\core\handlers\exception.py", line 41, in inner

    response = get_response(request)

  File "C:\Users\Administrator\.virtualenvs\py3.6-EAMp6_h3\lib\site-packages\django\core\handlers\base.py", line 187, in _get_response

    response = self.process_exception_by_middleware(e, request)

  File "C:\Users\Administrator\.virtualenvs\py3.6-EAMp6_h3\lib\site-packages\django\core\handlers\base.py", line 185, in _get_response

    response = wrapped_callback(request, *callback_args, **callback_kwargs)

  File "C:\Users\Administrator\.virtualenvs\py3.6-EAMp6_h3\lib\site-packages\django\contrib\auth\decorators.py", line 23, in _wrapped_view

    return view_func(request, *args, **kwargs)

  File "D:\Desktop\django1.11\project_mall\accounts\views.py", line 133, in user_address_edit

    'form': form

  File "C:\Users\Administrator\.virtualenvs\py3.6-EAMp6_h3\lib\site-packages\django\shortcuts.py", line 30, in render

    content = loader.render_to_string(template_name, context, request, using=using)

  File "C:\Users\Administrator\.virtualenvs\py3.6-EAMp6_h3\lib\site-packages\django\template\loader.py", line 68, in render_to_string

    return template.render(context, request)

  File "C:\Users\Administrator\.virtualenvs\py3.6-EAMp6_h3\lib\site-packages\django\template\backends\django.py", line 66, in render

    return self.template.render(context)

  File "C:\Users\Administrator\.virtualenvs\py3.6-EAMp6_h3\lib\site-packages\django\template\base.py", line 207, in render

    return self._render(context)

  File "C:\Users\Administrator\.virtualenvs\py3.6-EAMp6_h3\lib\site-packages\django\template\base.py", line 199, in _render

    return self.nodelist.render(context)

  File "C:\Users\Administrator\.virtualenvs\py3.6-EAMp6_h3\lib\site-packages\django\template\base.py", line 990, in render

    bit = node.render_annotated(context)

  File "C:\Users\Administrator\.virtualenvs\py3.6-EAMp6_h3\lib\site-packages\django\template\base.py", line 957, in render_annotated

    return self.render(context)

  File "C:\Users\Administrator\.virtualenvs\py3.6-EAMp6_h3\lib\site-packages\django\template\loader_tags.py", line 177, in render

    return compiled_parent._render(context)

  File "C:\Users\Administrator\.virtualenvs\py3.6-EAMp6_h3\lib\site-packages\django\template\base.py", line 199, in _render

    return self.nodelist.render(context)

  File "C:\Users\Administrator\.virtualenvs\py3.6-EAMp6_h3\lib\site-packages\django\template\base.py", line 990, in render

    bit = node.render_annotated(context)

  File "C:\Users\Administrator\.virtualenvs\py3.6-EAMp6_h3\lib\site-packages\django\template\base.py", line 957, in render_annotated

    return self.render(context)

  File "C:\Users\Administrator\.virtualenvs\py3.6-EAMp6_h3\lib\site-packages\django\template\loader_tags.py", line 72, in render

    result = block.nodelist.render(context)

  File "C:\Users\Administrator\.virtualenvs\py3.6-EAMp6_h3\lib\site-packages\django\template\base.py", line 990, in render

    bit = node.render_annotated(context)

  File "C:\Users\Administrator\.virtualenvs\py3.6-EAMp6_h3\lib\site-packages\django\template\base.py", line 957, in render_annotated

    return self.render(context)

  File "C:\Users\Administrator\.virtualenvs\py3.6-EAMp6_h3\lib\site-packages\django\template\defaulttags.py", line 458, in render

    url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)

  File "C:\Users\Administrator\.virtualenvs\py3.6-EAMp6_h3\lib\site-packages\django\urls\base.py", line 91, in reverse

    return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))

  File "C:\Users\Administrator\.virtualenvs\py3.6-EAMp6_h3\lib\site-packages\django\urls\resolvers.py", line 497, in _reverse_with_prefix

    raise NoReverseMatch(msg)

django.urls.exceptions.NoReverseMatch: Reverse for 'user_address_delete' with arguments '(None,)' not found. 1 pattern(s) tried: ['acc/user/address/delete/(?P<pk>\\d+)/$']

[14/Sep/2019 17:53:54] "GET /acc/user/address/edit/add/ HTTP/1.1" 500 163698


正在回答

登陆购买课程后可参与讨论,去登陆

1回答

同学,你好。报错信息为在页面渲染的时候出现了问题,添加地址的页面出现了删除地址的操作,反向解析是传入的参数为None,因此会报错。

在删除此地址的地方引入了javascript,js是在当前页面加载后才会加载,但是由于http://img1.sycdn.imooc.com//climg/5d7ef4a30939844a03820032.jpg直接就是在浏览器加载后直接加载。

但是我们注册时新用户没有地址。所以

http://img1.sycdn.imooc.com//climg/5d7ef4c00965220806280040.jpg

用户的地址id获取不到,所以返回None。

我们需要对此代码进行一些修改。

http://img1.sycdn.imooc.com//climg/5d7ef4f509ae983f09340287.jpg

同学按照上面的修改即可。

如果我解决了同学的问题,请采纳!祝学习愉快^_^。

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
3.从网页搭建入门Python Web
  • 参与学习           人
  • 提交作业       218    份
  • 解答问题       3562    个

本阶段带你用Python开发一个网站,学习主流框架Django+Flask是Python Web开发的第一步,在基础知识上实现积分商城的项目开发,体验真实的项目开发流程,提高解决编程问题和效率的能力。

了解课程
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师