呈现错误:反向查找“ ph”,未找到任何参数。尝试了1个模式:['(?P <answer> [^ /] +)/ ph \\-data / $']

时间:2018-12-24 03:44:08

标签: django url-parameters

我是编码的新手,在这里,我试图构建一个网站,将用户想要从选定范围内看到的内容简单地带进去,因为我运行服务器时会遇到此错误:

java.lang.ExceptionInInitializerError
    at javafx.web/javafx.scene.web.WebEngine.<clinit>(WebEngine.java:339)
    at javafx.web/javafx.scene.web.WebView.<init>(WebView.java:260)
    // omitting unrelated stacktraces
    at javafx.base/com.sun.javafx.event.CompositeEventHandler$NormalEventFilterRecord.handleCapturingEvent(CompositeEventHandler.java:282)
    at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchCapturingEvent(CompositeEventHandler.java:98)
    at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchCapturingEvent(EventHandlerManager.java:223)
    at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchCapturingEvent(EventHandlerManager.java:180)
    at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchCapturingEvent(CompositeEventDispatcher.java:43)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:52)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
    at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
    at javafx.graphics/javafx.scene.Scene$KeyHandler.process(Scene.java:4058)
    at javafx.graphics/javafx.scene.Scene$KeyHandler.access$1500(Scene.java:4004)
    at javafx.graphics/javafx.scene.Scene.processKeyEvent(Scene.java:2121)
    at javafx.graphics/javafx.scene.Scene$ScenePeerListener.keyEvent(Scene.java:2595)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:217)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:149)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleKeyEvent$1(GlassViewEventHandler.java:248)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:390)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleKeyEvent(GlassViewEventHandler.java:247)
    at javafx.graphics/com.sun.glass.ui.View.handleKeyEvent(View.java:547)
    at javafx.graphics/com.sun.glass.ui.View.notifyKey(View.java:971)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.UnsupportedOperationException: not implemented
    at javafx.base/com.sun.javafx.logging.PlatformLogger.getName(PlatformLogger.java:121)
    at javafx.web/com.sun.webkit.perf.PerfLogger.fullName(PerfLogger.java:155)
    at javafx.web/com.sun.webkit.perf.PerfLogger.registerProbe(PerfLogger.java:201)
    at javafx.web/com.sun.webkit.perf.PerfLogger.startCount(PerfLogger.java:227)
    at javafx.web/com.sun.webkit.perf.PerfLogger.<init>(PerfLogger.java:90)
    at javafx.web/com.sun.webkit.perf.PerfLogger.getLogger(PerfLogger.java:57)
    at javafx.web/com.sun.webkit.perf.PerfLogger.getLogger(PerfLogger.java:84)
    at javafx.web/com.sun.webkit.Invoker.<clinit>(Invoker.java:34)
    ... 37 more

对不起,我这么简单地问了一个问题

我尝试过的:

  1. 尝试swtich到pk:到

  2. 尝试添加到子弹或

我阅读了以下网址链接:Django - getting Error "Reverse for 'detail' with no arguments not found. 1 pattern(s) tried:" when using {% url "music:fav" %}

我的代码:

“我的观看”代码:

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/

Django Version: 2.1.3
Python Version: 3.7.1
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'rest_framework',
 'zigview']
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.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']


Template error:
In template C:\Users\user\Desktop\Frouniter\FrounterWeb- postgreDB\zigview\templates\FrounterWeb\index.html, error at line 12
   Reverse for 'ph' with no arguments not found. 1 pattern(s) tried: ['(?P<answer>[^/]+)/ph\\-data/$']
   2 : <html lang="en">
   3 : <head>
   4 :      {%load staticfiles%}
   5 :      <!-- Mobile resizing  and bootstrap -->
   6 :      {%include 'FrounterWeb/Lib-includes/Mobile-Response.html'%}
   7 : 
   8 :              <!-- Javascript action-->
   9 :      {%include 'FrounterWeb/Lib-includes/JavaScript-action.html'%}
   10 : 
   11 :                 <!-- Libary of chart and gage  -->
   12 :         {%include 'FrounterWeb/Lib-includes/Gr aphs-files.ht ml'%}
   13 : 
   14 :         <link rel="shortcut icon" type="image/png" href="{% static 'FrounterWeb/img/Logo.png' %}">
   15 :         <title>Frounter-Agrotech monitoring</title>
   16 : 
   17 : 
   18 : 
   19 : 
   20 :     </head>
   21 : 
   22 : <body class="body" style="background-color:#f6f6f6">


Traceback:

File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\handlers\exception.py" in inner
  34.             response = get_response(request)

File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\handlers\base.py" in _get_response
  156.                 response = self.process_exception_by_middleware(e, request)

File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\handlers\base.py" in _get_response
  154.                 response = response.render()

File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\template\response.py" in render
  106.             self.content = self.rendered_content

File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\template\response.py" in rendered_content
  83.         content = template.render(context, self._request)

File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\template\backends\django.py" in render
  61.             return self.template.render(context)

File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\template\base.py" in render
  171.                     return self._render(context)

File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\template\base.py" in _render
  163.         return self.nodelist.render(context)

File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\template\base.py" in render
  937.                 bit = node.render_annotated(context)

File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\template\base.py" in render_annotated
  904.             return self.render(context)

File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\template\loader_tags.py" in render
  150.             return compiled_parent._render(context)

File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\template\base.py" in _render
  163.         return self.nodelist.render(context)

File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\template\base.py" in render
  937.                 bit = node.render_annotated(context)

File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\template\base.py" in render_annotated
  904.             return self.render(context)

File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\template\defaulttags.py" in render
  309.                 return nodelist.render(context)

File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\template\base.py" in render
  937.                 bit = node.render_annotated(context)

File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\template\base.py" in render_annotated
  904.             return self.render(context)

File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\template\loader_tags.py" in render
  62.                 result = block.nodelist.render(context)

File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\template\base.py" in render
  937.                 bit = node.render_annotated(context)

File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\template\base.py" in render_annotated
  904.             return self.render(context)

File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\template\defaulttags.py" in render
  442.             url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)

File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\urls\base.py" in reverse
  90.     return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))

File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\urls\resolvers.py" in _reverse_with_prefix
  622.         raise NoReverseMatch(msg)

Exception Type: NoReverseMatch at /
Exception Value: Reverse for 'ph' with no arguments not found. 1 pattern(s) tried: ['(?P<answer>[^/]+)/ph\\-data/$'] 

应用URl代码:

    try:
     class index(ListView):
     model = tank_system
     template_name = 'FrounterWeb/extends/includes.html'
     ordering = ['-datetime']

    def get_context_data(self,**kwargs):
        return{'tank':self.get_queryset()}
    #def get_queryset(self):
     #   return

     except:
   logger.error('index page request failed/errors')


 try:
class ph(ListView):
    model = tank_system
    template_name = 'FrounterWeb/extends/ph.html'
    context_object_name = tank_system
    ordering = ['-datetime'] # sort dates in descending order

    def post(self, request, answer):
        if request.method == 'POST':
            form = YourForm(request.POST)

            if form.is_valid():
                answer = form.cleaned_data['value']


    def get_context_data(self, **kwargs):
        #do a selection of which path to do 
        return{'tank': self.get_queryset()}

    except:
     logger.error('PH page Functions failed/errors')

我的HTML代码供用户输入数据:

        from django.urls import path
        from . import views #function views
        path(r'<str:answer>/ph-data/', login_required(views.ph.as_view()), name='ph'),

总结什么结果:

我希望能够接受变量,并且也许现在可以从控制台中看到,该变量将传递到python脚本中,并使用它来选择数据,月份和年份以查看

1 个答案:

答案 0 :(得分:3)

您的问题似乎是(function () { var $tabNavigation = $(".feature-tabs a"); if ($tabNavigation.length > 0) { $tabNavigation.on("click", function (e) { $('body').find('.feature-tabs li').each(function (index, value) { $(value).removeClass('active'); }) $(this).tab("show"); $('body').find('.tab-panel').each(function (index, value) { if (!$(value).hasClass('active')) { $(this).addClass('hidden'); } else { $(this).removeClass('hidden'); } }) e.preventDefault(); return false; }); } })(); 在模板渲染时未定义(我看不到它被添加到任何上下文中)。在answer中有一个值之后,您应该可以执行以下操作:

answer

更新:OP不知道如何将{% url 'zigview:ph-data' answer=answer %} 添加到他的上下文字典中,因此我将在那部分进行扩展。要将其他值添加到上下文字典中,请将它们添加到基于类的视图的answer方法中:

get_context_data