Django错误“找不到'x'的反向。'x'不是有效的视图函数或模式名称。”,但x是模式名称

时间:2019-04-23 14:50:16

标签: python django django-2.0

我一直在使用Celery构建Django应用,并且我正在使用Javascript通过URL轮询本地数据库以获取Celery任务的状态。由于某些原因,我不断从脚本中的url模板标记中得到错误。我在做什么错了?

我已经仔细研究了SO上该问题的每一种变化,它们都归结为坏名声。据我所知,我的名字是正确的,并且我没有使用任何名称空间。

我的urls.py

    select row_number() over (order by min(id)) as rownumber,
           new_id as id,
           max(type) as type,
           max(case when category = 'Address' then value end) as address,
           max(case when category = 'City' then value end) as city,
           max(case when category = 'State' then value end) as state,
           max(case when category = 'Zip' then value end) as zip
    from (select t.*,
                 coalesce(id, max(id) over (order by rownumber)) as new_id
          from t
         ) t
    group by new_id;

令人反感的Javascript(layout.html)。

from django.conf.urls import url
from django.contrib.auth import views as auth_views
from django.views.generic.base import RedirectView
from django.urls import path, re_path
from django.conf import settings
from django.conf.urls.static import static
from django.contrib.staticfiles.urls import staticfiles_urlpatterns

import app.views

from django.conf.urls import include
from django.contrib import admin
admin.autodiscover()

urlpatterns = [
    path('signup/', app.views.signup, name='signup'),
    path('resetpassword/', auth_views.PasswordResetView.as_view(
        template_name='registration/resetpassword.html'), name="resetpassword"),
    path('password_reset/done/', auth_views.PasswordResetDoneView.as_view(
        template_name='registration/password_reset_done.html'), name='password_reset_done'),
    path('reset/<uidb64>/<token>/', auth_views.PasswordResetConfirmView.as_view(
        template_name='registration/resetpasswordconfirm.html'), name='password_reset_confirm'),
    path('reset/done/', auth_views.PasswordResetCompleteView.as_view(
        template_name='registration/resetpasswordcomplete.html'), name='password_reset_complete'),

    path('graph', app.views.draw_graph, name='graph'),
    path('upload', app.views.upload, name='upload'),
    path('download', app.views.download_zip),
    path('render', app.views.render_pulses, name='render'),
    path('display', app.views.display_images, name='display'),
    path('render_status', app.views.render_status, name='render-status'),
    path('', app.views.gallery, name='gallery'),

    re_path(r'^(?P<slug>[-\w]+)$', app.views.AlbumDetail.as_view(), name='album'),

    # Auth related urls
    re_path(r'accounts/login/$', auth_views.LoginView.as_view(), name='login'),
    re_path(r'accounts/logout/$', app.views.logout, {'next_page': '/', }, name='logout'),

    # Uncomment the next line to enable the admin:
    path('admin/', admin.site.urls),

    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

urlpatterns += staticfiles_urlpatterns()
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

handler404 = 'app.views.handler404'

所有功能都将导致的视图功能

<script type="text/javascript">// <![CDATA[
    function get_status() {
        var urlStatus = '{% url "render-status" %}';
        fetch().then(function(response) {
            response.json().then(function(data) {
                if(data.status) {
                    // show render link
                    // don't forget to hide on click
                }
                else {
                    // show loading gif
                }
            });
        });
        get_status();
// ]]></script>

最后,追溯

def render_status(request):
    result = db_API.get_render_status(request.user.id)

    return HttpResponse({'status': result}, content_type='application/json')

我希望它能够不断检查数据库中用户最新作业的状态,但会出错。

1 个答案:

答案 0 :(得分:0)

原来的错误是因为Gunicorn加载了早期版本的urls.py。我所做的所有更改都无济于事。为了修复它,我不得不重新启动守护程序。