请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

正在回答 回答被采纳积分+3

2回答

bobby 2018-10-15 09:51:05

users 这个报错的意思是你的users这个namespace没有注册,但是你在templates中使用了 users: 这种模式,所以你要看看你的全局url配置中的include的模式中的namespace是不是写错了,这个地方你可以仔细对一笔一下我的源码 https://git.imooc.com/coding-78/coding-78/src/master/MxOnlie/MxOnline/urls.py

0 回复 有任何疑惑可以回复我~
  • 提问者 慕UI3396178 #1
    哦这样子啊,然后我又往urls.py文件里加了
     #课程机构url配置
        url(r'^org/', include(('organization.urls','organization'), namespace="org")),
    这行代码可是它又提示我  ImportError: No module named urls
    我还有哪个地方要改?
    回复 有任何疑惑可以回复我~ 2018-10-15 20:29:51
  • bobby 回复 提问者 慕UI3396178 #2
    你的pycharm左侧代码导航结构我看看 有没有mark source root? 或者你试试organization.urls 将这个改为 apps.organization.urls试试
    回复 有任何疑惑可以回复我~ 2018-10-17 14:46:28
提问者 慕UI3396178 2018-10-13 11:11:03

还有这些

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/org-list/

Django Version: 1.9.8
Python Version: 2.7.15
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'users',
 'courses',
 'organization',
 'operation',
 'xadmin',
 'crispy_forms',
 'captcha']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']


Template error:
In template C:\Users\asus\PycharmProjects\MxOnline2\templates\org-list.html, error at line 53
   u'users' is not a registered namespace   43 :                     </div>
   44 :                 </li>
   45 :             </ul>
   46 :         </div>
   47 :         <div class="all">共<span class="key">{{ org_nums }}</span>家</div>
   48 :         <div class="butler_list company list">
   49 :         <div class="layout">
   50 :             <div class="head">
   51 :                 <ul class="tab_header">
   52 :                     <li class="{% if sort == '' %}active{% endif %}"><a href="?ct={{ category }}&city={{ city_id }}">全部</a> </li>
   53 :                     <li class="{% if sort  == 'students' %}active{% e ndif %}"><a href="?sort=students&ct={{ category }}&city={{ city_id }}">学习人数 &#8595;</a></li>
   54 :                     <li class="{% if sort == 'courses' %}active{% endif %}"><a href="?sort=courses&ct={{ category }}&city={{ city_id }}">课程数 &#8595;</a></li>
   55 :                 </ul>
   56 :             </div>
   57 :             {% for course_org in all_orgs.object_list %}
   58 :                 <dl class="des difdes">
   59 :                     <dt>
   60 :                         <a href="{% url 'org:org_home' course_org.id %}">
   61 :                             <img width="200" height="120" class="scrollLoading" data-url="{{ MEDIA_URL }}{{ course_org.image }}"/>
   62 :                         </a>
   63 :                     </dt>


Traceback:

File "C:\Users\asus\Envs\mxonline2\lib\site-packages\django\core\handlers\base.py" in get_response
  149.                     response = self.process_exception_by_middleware(e, request)

File "C:\Users\asus\Envs\mxonline2\lib\site-packages\django\core\handlers\base.py" in get_response
  147.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "C:\Users\asus\Envs\mxonline2\lib\site-packages\django\views\generic\base.py" in view
  68.             return self.dispatch(request, *args, **kwargs)

File "C:\Users\asus\Envs\mxonline2\lib\site-packages\django\views\generic\base.py" in dispatch
  88.         return handler(request, *args, **kwargs)

File "C:\Users\asus\PycharmProjects\MxOnline2\apps\organization\views.py" in get
  21.             "org_nums": org_nums

File "C:\Users\asus\Envs\mxonline2\lib\site-packages\django\shortcuts.py" in render
  67.             template_name, context, request=request, using=using)

File "C:\Users\asus\Envs\mxonline2\lib\site-packages\django\template\loader.py" in render_to_string
  97.         return template.render(context, request)

File "C:\Users\asus\Envs\mxonline2\lib\site-packages\django\template\backends\django.py" in render
  95.             return self.template.render(context)

File "C:\Users\asus\Envs\mxonline2\lib\site-packages\django\template\base.py" in render
  206.                     return self._render(context)

File "C:\Users\asus\Envs\mxonline2\lib\site-packages\django\template\base.py" in _render
  197.         return self.nodelist.render(context)

File "C:\Users\asus\Envs\mxonline2\lib\site-packages\django\template\base.py" in render
  992.                 bit = node.render_annotated(context)

File "C:\Users\asus\Envs\mxonline2\lib\site-packages\django\template\base.py" in render_annotated
  959.             return self.render(context)

File "C:\Users\asus\Envs\mxonline2\lib\site-packages\django\template\loader_tags.py" in render
  173.         return compiled_parent._render(context)

File "C:\Users\asus\Envs\mxonline2\lib\site-packages\django\template\base.py" in _render
  197.         return self.nodelist.render(context)

File "C:\Users\asus\Envs\mxonline2\lib\site-packages\django\template\base.py" in render
  992.                 bit = node.render_annotated(context)

File "C:\Users\asus\Envs\mxonline2\lib\site-packages\django\template\base.py" in render_annotated
  959.             return self.render(context)

File "C:\Users\asus\Envs\mxonline2\lib\site-packages\django\template\defaulttags.py" in render
  326.                 return nodelist.render(context)

File "C:\Users\asus\Envs\mxonline2\lib\site-packages\django\template\base.py" in render
  992.                 bit = node.render_annotated(context)

File "C:\Users\asus\Envs\mxonline2\lib\site-packages\django\template\base.py" in render_annotated
  959.             return self.render(context)

File "C:\Users\asus\Envs\mxonline2\lib\site-packages\django\template\defaulttags.py" in render
  513.                         six.reraise(*exc_info)

File "C:\Users\asus\Envs\mxonline2\lib\site-packages\django\template\defaulttags.py" in render
  499.             url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)

File "C:\Users\asus\Envs\mxonline2\lib\site-packages\django\core\urlresolvers.py" in reverse
  596.                                          key)

Exception Type: NoReverseMatch at /org-list/
Exception Value: u'users' is not a registered namespace

0 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信