反向搜索'没有找到参数。尝试了1种模式:[' $ search /']

时间:2017-10-05 20:14:59

标签: python django python-2.7 django-forms django-views

制作一个简单的网络剪贴板但卡住了这个问题。 最初看起来一切都很好看,因为我刚开始这个项目。我检查了应用提及和其他常见错误。如果我错过了什么,请指出我。

我收到此错误

NoReverseMatch at /
Reverse for 'search' with no arguments not found. 1 pattern(s) tried: 
['$search/']
Request Method: GET
Request URL:    http://127.0.0.1:8000/
Django Version: 1.11.5
Exception Type: NoReverseMatch
Exception Value:    
Reverse for 'search' with no arguments not found. 1 pattern(s) tried: 
['$search/']
Exception Location: C:\Program Files (x86)\Python36-32\lib\site-
packages\django\urls\resolvers.py in _reverse_with_prefix, line 497
Python Executable:  C:\Program Files (x86)\Python36-32\python.exe
Python Version: 3.6.3

我的urls.py是:

from django.conf.urls import url
from . import views
app_name = 'main'
urlpatterns = [
    url(r'^$', views.index, name='index'),
    url(r'^search/', views.search, name="search")
]

我的Views.py是:

from __future__ import unicode_literals
from django.http import HttpResponse
from django.template import loader

def index(request):
   template = loader.get_template('index.html')
   return HttpResponse(template.render({}, request))

def search(request):
   return HttpResponse('Hi There!')

我的表单就像这样

<form action="{% url 'main:search' %}" method="POST" class="form-horizontal">
    {% csrf_token %}
        <div class="form-group">
            <input type="url" id="input" class="form-control" name="iurl" placeholder="Enter Your Query" autocomplete="off" required><br>
            <input type="submit" value="SUBMIT" class="btn btn-primary btn-lg">
        </div>
    </form>

0 个答案:

没有答案