Beka
Yeah in the front end I want to show that liked or not... Got it?
Override the method get_context data and pass to context. Use that context in your template with if statements.
Human
But if it was one queryset object I can do the condition... But when its a list of query set... How to do that for each objects?
Human
Using Annotate?
Human
Likes = ManytoManyfield(User) this is what I have... In model... I need to check in each post that the user id is in the many to many field.
Human
Omg... 😅 Why is this really difficult to convey...
Beka
You're jumping from one issue to another... concentrate and fix one issue))
Human
Bro, In the get_context_data we will get the queryset.... Which will be the list of objects of Posts. In the Posts Model I have Likes = models.ManytoManyField(User) So there will be many users who liked the post... I need to check the current user is liked(in many tomany field the user id should be there.) So how to check it and send it to frontend...
Human
Then only I can show that the post is already liked or not in front end...
Human
Like and unlike is working fine. But I'm not able to show whether the post is liked or not.
Beka
{% for post in posts %} <div> <p>{{ post.tweet }}</p> {% if post.liked_by_user %} <p>Liked by you!</p> {% else %} <button onclick="likePost({{ post.id }})">Like</button> {% endif %} </div> {% endfor %}
Beka
Sorry, by solution is still the same. Use Ajax request for onclick and I've already sent the handling ajax request. That's all from me. Thank you
Beka
and good luck*
Human
Bro you used liked_by_user in the for loop but how it's actually work? There is no variable like that.
Human
Thank you Devs.... Thank you very much... It worked well... The change I made was in the for loop {% for post in object_list %} {% if request.user in i.likes.all %} # user is liked {% endif %}
Beka
Bro you used liked_by_user in the for loop but how it's actually work? There is no variable like that.
Sorry forgot to send you the updated view but glad you've figured out.
Beka
Thank you Devs.... Thank you very much... It worked well... The change I made was in the for loop {% for post in object_list %} {% if request.user in i.likes.all %} # user is liked {% endif %}
Congrats! Now do it with Ajax)) Very good case for your issue now with Ajax. It's just a recommendation to improve your functionality code.
Human
Okay thanks
Simon
I am creating a registration application. I have a problem, if the user enters his email and password and submits, a new user will be created and he will be given an access and refresh token. And then a verification code will be sent to him. Here the user introduces himself with the access token. What happens if the refresh token expires here. He cannot proceed to the login page until he confirms the code.
The Inspired
I am creating a registration application. I have a problem, if the user enters his email and password and submits, a new user will be created and he will be given an access and refresh token. And then a verification code will be sent to him. Here the user introduces himself with the access token. What happens if the refresh token expires here. He cannot proceed to the login page until he confirms the code.
That is why you keep the active duration of refresh token a little longer than access token. For e.g. if your access token expires after 24 hours, make sure your refresh token expires after 48 hours. This is so that when your acess token expires, you can send another request using the refresh token and generate a new access token
Shriraj
Why is my django website not fetching CSS properties
Shriraj
It' show plain HTML structure and a image which isnt really alligned
Doragonsureiyā
Why is my django website not fetching CSS properties
Impossible to help without details. Read this please: http://www.catb.org/~esr/faqs/smart-questions.html
Shriraj
Details as in dejango which details?
pranav
Beka
Yes, that's for sure. But what if the refresh token expires?
Better to confirm the code in duration of refresh token. Even, after that no code confirmed, just register again. You may need to update register logic including token case.
Shriraj
The code and everything
Which django files to send?
pranav
Which django files to send?
File related to your issue
The Inspired
Yes, that's for sure. But what if the refresh token expires?
In that case, you can increase the duration of refresh token
The Inspired
or just logout the user if both of it expires. he will have to log in again and get the tokena freshly
Charly
Is it possible to explain more precisely?
I'm basically asking you what would be the purpose of rabbitmq in your project
Simon
or just logout the user if both of it expires. he will have to log in again and get the tokena freshly
Yes, this is clear, but if the code is not validated, the project will not go to the login page
king
Hello please I wanted to ask Can one create a fully customized admin panel with Django?or the default admin panel is a must in all Django apps
king
Tom
Guys. Can you please suggest the best resources to learn django (project based). Either ebooks or Udemy courses
Doragonsureiyā
Guys. Can you please suggest the best resources to learn django (project based). Either ebooks or Udemy courses
Looking for Django tutorials? you can follow these three recommended ones: * Official documentation and tutorial * Tutorial from MDN * Tutorial from django-girls
Simon
I am creating a registration application. I have a problem, if the user enters his email and password and submits, a new user will be created and he will be given an access and refresh token. And then a verification code will be sent to him. Here the user introduces himself with the access token. What happens if the refresh token expires here. He cannot proceed to the login page until he confirms the code.
Fritz Flores
Does anybody have a tutorial on how to deploy a Django website on VPS hostinger ? I’m having trouble setting it up.
Samir Arvind Saitwal
Did anyone has project which will provide how to develop web socket in django? If yes please share links
#
Does any boy can help me with this ? Our project currently following the restframework simple jwt . Libraray for authentication Basically user send email and password we are returning a jwt acces token as response With using that token access token he can able to access all the API s passing jwt as bearer token in headers This approcah we are following on 2 projects Now i need to creat one django app that should act as like SSO (single sign on ) valid for both projects like sharing one jwt token per user to access both project apis. Can anybody help me atleast rough idea or suggested articles.
Majid
Django 5 by example pdf Any body can help me to do it?
Aditya
Can anyone help me in completing thus
Doragonsureiyā
Can anyone help me in completing thus
This group is to help you on specific issues you have on YOUR code, so you have to show the code you wrote and explain where and why you are stuck... as simple as that
_PRANAV_
It' show plain HTML structure and a image which isnt really alligned
Did you try to copy and paste the entire css code at once??
Shriraj
Didn't do any changes to any css files
_PRANAV_
I cloned the git hub repo bro
May be it's due to the cache related issues , may be
Mirco
Django 5 by example pdf Any body can help me to do it?
Buy it, we don't support piracy here
Doragonsureiyā
This is not a Django specific question, please delete your offtopic message. If it's a Python related question go to @Python group, otherwise please move to @PythonOfftopic group and ask there.
Aditya
How to properly develope chat application backend using django rest api
Doragonsureiyā
How to properly develope chat application backend using django rest api
Read this please: http://www.catb.org/~esr/faqs/smart-questions.html
-sobhan
I'm basically asking you what would be the purpose of rabbitmq in your project
I have a microservices project where I have to write Django services and someone else NodeJS services using Rabbitmq Contact Do you have experience to show me some code? Thanks
Charly
I have a microservices project where I have to write Django services and someone else NodeJS services using Rabbitmq Contact Do you have experience to show me some code? Thanks
I have experience but I can't show you code search about it. In the Django part is just a message producer not really a micro service (Django is not for micro services)
AT
Hello I’m new to Django, although I learnt python Basic already, do I need to learn Java and HTML too. Or there would be no need
AT
you're probably confusing Java with JavaScript
I don’t really know much about other languages, I focused on python only, and from the introduction To Django I’ve seen, it seems I won’t be needing python alone, that’s where I’m confused
tan (θ)
can anyone recommend me better frontend libraries for django beyond those 1. bootstrap / tailwind 2. htmx 3. alpine.js
Charly
Use whatever you want but here we don't discuss frontend development
Григорий
Why do many programmers dislike using django when creating websites? Is it slow?
Nagpur_cha_rahivasi
Why do many programmers dislike using django when creating websites? Is it slow?
Developers familiarity with the framework is the issue. Not many people know about Django Stack.
Charly
Why do many programmers dislike using django when creating websites? Is it slow?
Django is not for creating websites it is for dynamic web applications
Rober
Actually is the most popular python framework
Fastapi and flask are known because Django exists jaja
pranav
Developers familiarity with the framework is the issue. Not many people know about Django Stack.
What is django stack? Like tell me the tech stack in django stack?
Nagpur_cha_rahivasi
What is django stack? Like tell me the tech stack in django stack?
I use STACK :- HTML , CSS , JS , PYTHON , DJANGO. I would like experienced folks present in this group to SHARE THEIR STACKS.
pranav
I use STACK :- HTML , CSS , JS , PYTHON , DJANGO. I would like experienced folks present in this group to SHARE THEIR STACKS.
These are basics and must , I wanted to know if there is something else in your stack , anyway thanks
Swetty
Why my djangoapp (home) cant read my static files, but getting access to media and django admin can read static files with media? p.s. python manage.py collectstatic has done tree&logs&code here - https://paste.aiogram.dev/aduyogawik.csharp