Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.7k views
in Technique[技术] by (71.8m points)

Django携带参数id跳转页面出现错误

错误信息:Reverse for 'org_detail' with no arguments not found. 1 pattern(s) tried: ['orgs/org_detail/(d+)/$']
views.py

def org_detail(request, org_id):
    if org_id:
        org = OrgInfo.objects.filter(id=int(org_id))[0]
 return render(request, 'orgs/org-detail-homepage.html', {
 'org': org
        })

org-list.html

{% url 'orgs:org_detail' org.id %}
{% for org in pages %}
 <dl class="des difdes">
 <dt>
 <a href="{% url 'orgs:org_detail' org.id %}">
 <img width="200" height="120" class="scrollLoading"
 data-url="{{ MEDIA_URL }}{{ org.image }}"/>
 </a>
 </dt>
 <dd>
 <div class="clearfix">
 <a href="{% url 'orgs:org_detail' org.id %}">
 <h1>{{ org.name }}</h1>
 <div class="pic fl">
 <img src="{% static 'images/authentication.png' %}"/>
 <img src="{% static 'images/gold.png' %}"/>
 </div>
 </a>
 </div>
 <ul class="cont">
 <li class="first"><p class="pic9">课程数:<span>{{ org.course_num }}</span></p>
 <p class="c7">学习人数:<span>{{ org.study_num }}</span></p></li>
 <li class="c8" style="padding-left:18px;">{{ org.address }}</li>
 <li class="pic10" style="padding-left:18px;">经典课程:
 {% for course in org.courseinfo_set.all|slice:":2" %}
 <a href="/diary/19/">{{ course.name }}</a>
 {% endfor %}
 </li>
 </ul>
 </dd>
 <div class="buy start_groupbuy jsShowPerfect2" data-id="22"><br/>联系<br/>服务</div>
 </dl>
{% endfor %}

urls.py

from django.urls import path, re_path
from orgs import views
app_name = 'orgs'
urlpatterns = [
 re_path('org_list/$', views.org_list, name='org_list'),
    re_path('org_detail/(d+)/$', views.org_detail, name='org_detail'),
]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...