Re: How to create chatroom?

2020-05-27 Thread Motaz Hejaze
Read about django channels

On Wed, 27 May 2020, 1:30 pm meera gangani, 
wrote:

> I want to create chatroom in django like slack, where user can post
> messages to the room and at the same time other user can see those message
> immediately
>
> What Can I Do?
> And What are the Libraries I install?
> Please Help Me Out!!
>
>
> Thanks In Advance
> -Meera Gangani
>
> --
> 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/CANaPPP%2BriRwafC3SCJptEZEy3S9iKgJPA0WDoMjvABWCfw6Rzw%40mail.gmail.com
> 
> .
>

-- 
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/CAHV4E-c%3DWv59y5acTYcZnfQ%3Dct1VWL8Y99EA2Juk0cYMx%3DvORw%40mail.gmail.com.


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

2020-05-20 Thread Motaz Hejaze
Change your ajax method from "post" to "get" , you are not submitting any
data to use post .

Also change the method in your form too , and share the error message
please.

On Wed, 20 May 2020, 6:18 am Ahmed Khairy, 
wrote:

> Do you mean that this line should be changed?
>
>  'post_id' class= "btn btn-danger btn-sm" value="{{post.id}}"
> > 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>
>>>
>>>