Django URL模式没有出现在生产中,找不到页面

时间:2016-10-24 23:04:29

标签: python django url routing urlconf

问题

我为代理商页面创建了一个网址格式,在本地工作正常,但在项目推送到生产时却没有。尝试调试错误时,网页模式不会显示在404页面url(r'^agencies/$', views.agencies, name='agencies')

_home.html

 <div class="cards">
                <a href="agencies/">
                <div class="card card--earners">
                    <img src="{% static 'salaries/img/building.png' %}" class="card__icon">
                    <p class="card__title">Agencies</p>
                    <p class="card__desc">Find salary information for public safety workers, government employees and elected officials.</p>
                </div>
                </a>

                <a href="teachers/">
                <div class="card card--salary">
                    <img src="{% static 'salaries/img/school.png' %}" class="card__icon">
                    <p class="card__title">Schools</p>
                    <p class="card__desc">Find salary information for superintendents, principals and teachers in Missouri public schools.</p>
                </div>
                </a>
            </div>

找不到页面

Using the URLconf defined in payrolls.urls, Django tried these URL patterns, in this order:
^salaries/ ^$ [name='home']
^salaries/ ^(?P<agency_id>[0-9]+)/$ [name='agency']
^salaries/ ^(?P<department_id>[0-9]+_[0-9]+)/$ [name='department']
^salaries/ ^(?P<agency_id>[0-9]+)/agency_search/$ [name='agency_search']
^salaries/ ^master_search/$ [name='master_search']
^salaries/ ^teachers/$ [name='teachers']
^salaries/ ^teachers/(?P<district_id>[0-9]+)/$ [name='district']
^salaries/ ^teachers/(?P<district_code>[0-9]+)/(?P<school_code>[0-9]+)/$ [name='school']
^salaries/ ^teachers/(?P<district_code>[0-9]+)/position/(?P<position_code>[0-9]+)/$ [name='dist_position']
^salaries/ ^teachers/(?P<district_code>[0-9]+)/(?P<school_code>[0-9]+)/position/(?P<position_code>[0-9]+)/$ [name='school_position']
^salaries/ ^educator_search/$ [name='educator_search']
^salaries/ ^teachers/(?P<district_id>[0-9]+)/district_search/$ [name='district_search']
^salaries/ ^teachers/detail/(?P<teacher_id>[0-9]+)/$ [name='person']
^admin/
The current URL, salaries/agencies/, didn't match any of these.

urls.py

from django.conf.urls import url

from salaries import views

urlpatterns = [
    url(r'^$', views.home, name='home'),
    url(r'^(?P<agency_id>[0-9]+)/$', views.agency, name='agency'),
    url(r'^(?P<department_id>[0-9]+_[0-9]+)/$', views.department, name='department'),
    url(r'^(?P<agency_id>[0-9]+)/agency_search/$', views.agency_search, name='agency_search'),
    url(r'^master_search/$', views.master_search, name='master_search'),
    url(r'^teachers/$', views.teachers, name='teachers'),
    url(r'^teachers/(?P<district_id>[0-9]+)/$', views.district, name='district'),
    url(r'^teachers/(?P<district_code>[0-9]+)/(?P<school_code>[0-9]+)/$', views.school, name='school'),
    url(r'^teachers/(?P<district_code>[0-9]+)/position/(?P<position_code>[0-9]+)/$', views.dist_position, name='dist_position'),
    url(r'^teachers/(?P<district_code>[0-9]+)/(?P<school_code>[0-9]+)/position/(?P<position_code>[0-9]+)/$', views.school_position, name='school_position'),
    url(r'^educator_search/$', views.educator_search, name='educator_search'),
    url(r'^teachers/(?P<district_id>[0-9]+)/district_search/$', views.district_search, name='district_search'),
    url(r'^teachers/detail/(?P<teacher_id>[0-9]+)/$', views.person, name='person'),
    url(r'^agencies/$', views.agencies, name='agencies'),
]

views.py

def agencies(request):
    agency_list = Agency.objects.all().order_by('-headcount')

    top_earners = []

    for agency in agency_list:

        top_earners.append(Employee.objects.filter(agency_unique=agency.id).order_by("-salary")[0])

    context = {'agencies': agency_list, 'top_earners': top_earners}

    return render(request, 'salaries/agencies.html', context)

0 个答案:

没有答案