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

2020-05-19 Thread ratnadeep ray
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 %}
>   Display the test results
>   
> 
> SQL
>   
> {% 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 django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/31ce205c-b54c-484f-8928-350eb91178a6%40googlegroups.com.


Re: Can't Fix the No Reverse Error in Ajax

2020-05-19 Thread Ahmed Khairy
Do you mean that this line should be changed?

 No ! Don't Print it 

On Tuesday, May 19, 2020 at 11:11:12 PM UTC-4, Hella Nick wrote:
>
> button标签中的type属性设置为button,
>
> Ahmed Khairy > 于2020年5月20日周三 上午1:54写道:
>
>> I am trying to use Ajax to submit a like button, I believe everything is 
>> in order but I keep getting django.urls.exceptions.NoReverseMatch: Reverse 
>> for 'like_post' with arguments '('',)' not found. 1 pattern(s) tried: 
>> ['score/like/(?P[0-9]+)$']
>>
>>
>> I am not sure what is the reason. Need help to identify the error.
>>
>>
>> Here is the view
>>
>>
>> class PostDetailView(DetailView):
>> model = Post
>> template_name = "post_detail.html"
>>
>> def get_context_data(self, *args, **kwargs):
>> context = super(PostDetailView, self).get_context_data()
>> stuff = get_object_or_404(Post, id=self.kwargs['pk'])
>> total_likes = stuff.total_likes()
>> liked = False
>> if stuff.likes.filter(id=self.request.user.id).exists():
>> liked = True
>> context["total_likes"] = total_likes
>> context["liked"] = liked
>> return context
>>
>>
>> def LikeView(request, pk):
>> # post = get_object_or_404(Post, id=request.POST.get('post_id'))
>> post = get_object_or_404(Post, id=request.POST.get('id'))
>> like = False
>> if post.likes.filter(id=request.user.id).exists():
>> post.likes.remove(request.user)
>> like = False
>> else:
>> post.likes.add(request.user)
>> like = True
>> context["total_likes"] = total_likes
>> context["liked"] = liked
>>
>> if request.is_ajax:
>> html = render_to_string('like_section.html', context, request=
>> request)
>> return JsonResponse({'form': html})
>>
>> Here is the url.py updated
>>
>> urlpatterns = [
>> path('user/', UserPostListView.as_view(), name=
>> 'user-posts'),
>> path('', PostListView.as_view(), name='score'),
>> path('who_we_Are/', who_we_are, name='who_we_are'),
>> path('/', PostDetailView.as_view(), name='post-detail'),
>> path('like/', LikeView, name='like_post'),
>> path('new/', PostCreateView.as_view(), name='post-create'),
>> path('/update/', PostUpdateView.as_view(), name='post-update'
>> ),
>> path('/delete/', PostDeleteView.as_view(), name='post-delete'
>> )
>> ]
>>
>> here is the template
>>
>> 
>> {% csrf_token %}
>>  Likes: {{total_likes}}  
>> {% if user.is_authenticated %}
>> {% if liked %}
>> > 'post_id' class= "btn btn-danger btn-sm" 
>> value="{{post.id}}"> Unlike 
>> {% else %}
>> > 'post_id' class= "btn btn-primary btn-sm" 
>> value="{{post.id}}"> Like 
>> {% endif  %}
>> {% else %}
>> > > Login to Like 
>> {% endif %}   
>>
>>
>> here is the ajax
>>
>> https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js";>> script>
>> 
>>