Reverse for 'process_data' not found. 'process_data' is not a valid view function or pattern name.

62 views
Skip to first unread message

ratnadeep ray

unread,
Jun 24, 2020, 9:26:43 AM6/24/20
to Django users
Hi all, 

I am trying to direct the option selected from the dropdown in the index.html along with the value to the process_data method in the views.py. But now I am getting the following error when I am trying to load my index page: 

NoReverseMatch at /index/

Reverse for 'process_data' not found. 'process_data' is not a valid view function or pattern name.



My index.html file is as follows: 

<html lang="en">
<head>
   
<meta http-equiv="CONTENT-TYPE" content="text/html; charset=utf-8">
   
<title>Home</title>
</head>
<body>
 
<center>
 
<h3>Index page</h3>
 
<table align='center'>
 
<tr><td>Select the version to compare with</td><td>
 
<select name="version" id="version" onchange="location = this.value;">
 
<option>Select version to compare with</option>
 {%for ver in version_list%}
 
<option value={{ver}} href="{% url 'process_data' ver %}">{{ver}}</option>
 {% endfor %}
 
</select>
 
</td></tr>
 
<tr><td>The current version</td><td>{{version}}</td>
 
</tr>
 
</table>
 
<br><br><br>
</body>
</html>

My view file content is like this: 

def index(request):
    #query_results = QRC_DB.objects.all()
    global percentage_variation
    percentage_variation = 0
    global version
    version = None 
    context = RequestContext(request)
    response_context = get_result(request)
    #print("The response_context values  = \n %s" %response_context.get("get_result"))
    cursor  = connection.cursor()
    cursor.execute("select version from fusioncharts_qrc_db group by version")
    rows = cursor.fetchall()
    #print("The fetched rows =\n")
    #print(rows)
    version_list = []
    #print(version_list)
    for ver in rows:
        version = str(ver).split("'")[1]
        version_list.append(version)

    print("The final version list = %s" %version_list)
    return render(request, 'index.html', {
        'version': version, 
        'version_list': version_list,        
        })


def process_data(request,ver):
   
   
print("==============The version selected = %s===========" %ver)

   
return render(request, 'display_data.html', {
       
'version': version,
     
       
})


The url file contents are as follows: 

from django.urls import path
from fusioncharts import views


urlpatterns
= [
    path
('push-data/', views.push_data, name='push-data'),
    path
('home/', views.home, name='home'),
    path
('display_data/<str:component>', views.display_data, name='display_data'),
    path
('index/', views.index, name='index'),
]

from django.contrib import admin
from django.urls import path,include


urlpatterns
= [
    path
('admin/', admin.site.urls),
    path
('', include('fusioncharts.urls'))
]

Can anyone please help me why the above error is coming and how to fix that ? 

ratnadeep ray

unread,
Jun 24, 2020, 1:22:05 PM6/24/20
to Django users
Hi all,

Any comment on this?

Ogunsanya Opeyemi

unread,
Jun 24, 2020, 1:56:42 PM6/24/20
to django...@googlegroups.com
You do not have a URL for process_data that you want to access, that is why it is saying no valid view name process_data


On Wednesday, June 24, 2020, ratnadeep ray <ratna...@gmail.com> wrote:
Hi all,

Any comment on this?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/852e2f1b-fcfc-43a9-b098-9170579a8f56o%40googlegroups.com.


--
OGUNSANYA OPEYEMI

ratnadeep ray

unread,
Jun 24, 2020, 2:14:07 PM6/24/20
to Django users
So I need to add this also:

urlpatterns = [
...
...
path('process_data/', views.process_data, name='process_data'),

Ogunsanya Opeyemi

unread,
Jun 24, 2020, 2:55:17 PM6/24/20
to django...@googlegroups.com

Yes

On Wednesday, June 24, 2020, ratnadeep ray <ratna...@gmail.com> wrote:
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5c62826f-a652-43c3-a89e-29cf1855a9f8o%40googlegroups.com.


--
OGUNSANYA OPEYEMI

ratnadeep ray

unread,
Jun 25, 2020, 1:41:36 AM6/25/20
to Django users
Hi Ogunsanya, 

I have added that line of code but still getting the same error. 

So what can be done next ? 


On Thursday, 25 June 2020 00:25:17 UTC+5:30, Ogunsanya Opeyemi wrote:

Yes
On Wednesday, June 24, 2020, ratnadeep ray <ratna...@gmail.com> wrote:
So I need to add this also:



urlpatterns = [
    ...
    ...
    path('process_data/', views.process_data, name='process_data'),

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.


--
OGUNSANYA OPEYEMI

Ogunsanya Opeyemi

unread,
Jun 25, 2020, 2:38:12 AM6/25/20
to django...@googlegroups.com
Also include in your URL before your urlpatterns 

app_name=yourappname


And in your template URL  write
{% url 'yourappname:process_data' ver %}



And if you still have issues send the update you made and let me check.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bb999e9e-5fd9-45ec-9a59-86e3ed9b6454o%40googlegroups.com.


--
OGUNSANYA OPEYEMI

ratnadeep ray

unread,
Jun 25, 2020, 5:25:29 AM6/25/20
to Django users
Hi Ogunsanya,

Now I added the same as per your suggestion. Following is my urls.py contnent

from django.urls import path
from fusioncharts import
views
app_name
= 'fusioncharts'



urlpatterns
= [
    path
('push-data/', views.push_data, name='push-data'),
    path
('home/', views.home, name='home'),
    path
('display_data/<str:component>', views.display_data, name='display_data'),

    path
('index/', views.index, name=''),
    path('process_data/<str:ver>', views.process_data, name='process_data'),
]

And my template content (process_data.py)is as follows: 

<html lang="en">
<head>
   
<meta http-equiv="CONTENT-TYPE" content="text/html; charset=utf-8">
   
<title>Home</title>
</head>
<body>
 
<center>
 
<h3>Index page</h3>
 
<table align='center'>
 
<tr><td>Select the version to compare with</td><td>
 
<select name="version" id="version" onchange="location = this.value;">
 
<option>Select version to compare with</option>

 {%for ver in version_list%}
 
<option value={{ver}} href="{% url 'fusioncharts:process_data' ver %}">{{ver}}</option>

 {% endfor %}
 
</select>
 
</td></tr>
 
<tr><td>The current version</td><td>{{version}}</td>
 
</tr>
 
</table>
 
<br><br><br>
</body>
</html>


But now I am getting the following error: 

Page not found (404)

Request Method:GET
Request URL:http://127.0.0.1:8000/index/11.5.1.18900-96

http
://127.0.0.1:8000/index/11.5.1.18900-97


Using the URLconf defined in Piechart_Excel.urls, Django tried these URL patterns, in this order:
admin
/
push
-data/ [name='push-data']
home
/ [name='home']
display_data
/<str:component> [name='display_data']
index
/
process_data
/<str:ver> [name='process_data']

The current path, index/11.5.1.18900-96, didn't match any of these.


Can you suggest now what's going wrong ? 



Ogunsanya Opeyemi

unread,
Jun 25, 2020, 8:16:52 AM6/25/20
to django...@googlegroups.com
Look at your index path it is not written very well in the name you wrote name=') without closing the apstorphe ' and request a url purely in your template href like this href="process_data/{{ver}}".
And let me know wether it worked or not.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/14aca6b8-8bc9-455a-b3c6-de0c8740a9a7o%40googlegroups.com.


--
OGUNSANYA OPEYEMI

ratnadeep ray

unread,
Jun 26, 2020, 9:28:50 AM6/26/20
to Django users
Hi Ogunasya, 

I tried that but still that's not working. After some research and analysis, I realized the issue is not with the urls but with the html file. When I am trying to direct to the url in the href via drop-down only, the error is coming. But if we I am trying to access the same url via table, it is working fine. 

So to summarize: 
Working: 
<tr><td><a href="{% url 'process_data' ver1 %}">{{ver}}</a></td></tr>


Non-working: 
<option value={{ver}} href="{% url 'process_data' ver %}">{{ver}}</option>

Can you please suggest what is going wrong ? How can we reach the method 'process_data' using dropdown ? 

Ogunsanya Opeyemi

unread,
Jun 26, 2020, 2:25:23 PM6/26/20
to django...@googlegroups.com
Ok good job 👍

You can email me directly for any issue. 
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/db746050-5807-4b00-847f-3c3077faccb2o%40googlegroups.com.


--
OGUNSANYA OPEYEMI

Reply all
Reply to author
Forward
0 new messages