On Tue, May 19, 2020 at 10:56 PM ratnadeep ray <[email protected]> wrote:
> Hi all,
>
> I am getting the below error when I am trying to load the home page:
> Reverse for 'display_data' not found. 'display_data' is not a valid view
> function or pattern name
>
> My views.py file is as follows:
>
>
>
>> def home(request):
>> #query_results = QRC_DB.objects.all()
>> return render(request, 'display_data.html')
>>
>> def display_data(request,component):
>> #query_results = QRC_DB.objects.all()
>> return HttpResponse("You're looking at the component %s." % component)
>
>
> My urls.py file under the app is as follows:
>
> from django.urls import path
> from fusioncharts import views
>
> urlpatterns = [
>> path('home/', views.home, name=''),
>> ]
>
>
> The urls.py file under the project is as follows:
>
> from django.contrib import admin
>> from django.urls import path,include
>> urlpatterns = [
>> path('admin/', admin.site.urls),
>> path('', include('fusioncharts.urls'))
>> ]
>
>
>
> And my html file (display_data) code is as follows :
>
>>
>> {% block content %}
>> <h3>Display the test results</h3>
>> <div id="container" style="width: 75%;">
>> <canvas id="display-data"></canvas>
>> <li><a href="{% url 'display_data' 'SQL' %}">SQL</a></li>
>> </div>
>> {% endblock %}
>
>
>
>
> Can anyone please help me to find out the mistake ?
>
> Thanks.
>
>
>
>
>
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/31ce205c-b54c-484f-8928-350eb91178a6%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/31ce205c-b54c-484f-8928-350eb91178a6%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
NoReverseFound is one of those exceptions that I need a mental mapping
for. It's not necessarily easy to intuit the meaning from the name
itself. What works for me is that Django is saying "You've given me a
named URL, and I can't find it."
In your template, there's a url tag. The first argument of a url tag is the
named url it should insert there. You give the tag 'display_data', but
there is no urlpattern in either of your urls with the name set to
'display_data'.
In your fusioncharts/urls.py, I would add this (completely untested):
from django.urls import path
from fusioncharts import views
urlpatterns = [
> path('home/', views.home, name=''),
>
*path('display_data/<str:component>/', views.display_data,
name='display_data'), # <- Added here!*
> ]
Now we have a path with the same name that your template is looking for,
you have a view it sends the data to, and you capture the variable that
will be sent to the view.
Hope this helps!
-Jorge
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CANfN%3DK9wy5WFN4TEb6gapvQAkqYqM8G0mXKwFAzB1TLz-EUbuA%40mail.gmail.com.