猿问

Django+xadmin url找不到设置的路径匹配出错

报错问题描述: Reverse for 'home' with arguments '()' and keyword arguments '{}' not found. 1 pattern(s) tried: ['org/home/(?P<org_id>\\d+)/$']

urlpatterns = [
    # 机构首页
    url(r'^list/$', OrgView.as_view(), name="org_list"),
    url(r'^add_ask/$', AddUserAskView.as_view(), name="add_ask"),
    url(r'^home/(?P<org_id>\d+)/$', OrgHomeView.as_view(), name="home"),
]

....
#课程机构地址配置
url(r'^org/', include('organization.urls', namespace="org")),

...

class OrgHomeView(View):
    def get(self, request, org_id):
        course_org = CourseOrg.objects.get(id=int(org_id))
        all_courses = course_org.course_set.all()[:3]
        all_teachers = course_org.teacher_set.all()[:1]
        return render(request, 'org-detail-homepage.html',  {
            'all_courses': all_courses,
            'all_teachers': all_teachers
        })
<div class="brief group_list">
          {% for course in all_courses %}
              <div class="module1_5 box">
                  <a href="course-detail.html"><img width="214" src="{{ MEDIA_URL }}{{ course.image }}"/></a>
                  <div class="des">
                      <a href="course-detail.html"><h2>{{ course.name }}</h2></a>
                      <span class="fl">课时:<i class="key">{{ course.learn_time }}</i></span>
                      <span class="fr">参加人数:{{ course.students }}</span>
                  </div>
                  <div class="bottom">
                      <span class="fl">{{ course.course_org.name }}</span>
                       <span class="star fr  notlogin
                          " data-favid="13"  data-fav-type="4">
                          {{ course.favorite_student }}
                      </span>
                  </div>
              </div>
          {% endfor %}

希望大家能够帮助解答。谢谢

qq_人生的意义_0
浏览 2985回答 2
2回答

XO鸡丝

根据报错信息,应该是跳转时有问题. 比如多了一个 / ,没有传输到 org_id.你应该提供跳转到org/home的那段代码.

KIWI2018

我们有一样的问题呢
随时随地看视频慕课网APP

相关分类

Python
我要回答