0

Making a simple web scraper but stuck is this problem. At initial looks everything looks fine at my side as I've just started this project. I've checked the app mentioning and other common mistakes. Please point me out if I'm missing something.

I'm getting this error

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

My urls.py is:

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")
]

My Views.py is:

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!')

And My form goes like this

<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>
  • Can you add the `urls.py` file where you are including your app's urls? You may not be setting the namespace right – Brobin Oct 05 '17 at 20:18
  • Try this `url(r'^/', include('main.urls'))` instead `url(r'^$', include('main.urls'))` and add namespace to base `urls.py` – amarynets Oct 05 '17 at 20:26
  • ```python from django.conf.urls import url, include from django.contrib import admin urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^$', include('main.urls')), ] ``` – Subham Bhattacharjee Oct 05 '17 at 20:26
  • @AndMar url(r'^', include('main.urls')) this fixed all things. Thanks Bruh. What was happening can you tell me? – Subham Bhattacharjee Oct 05 '17 at 20:29

0 Answers0