R@kesh
What is pytest
R@kesh
It is an ide
#
What is pytest
To test the individual code snippets by importing pytest library it is similar to unit test
M Latif
Is there any good tutorials for? to perform pytest in django
I searched in n that tutorial i didn't find
#
I searched in n that tutorial i didn't find
https://docs.pytest.org/en/6.2.x/
Jap
How to i manage many2many selection from font form and nested categories in forms
Paul
Hi everyone, i am having a bad time understanding how can i redirect a user after editing a form to be redirected to the same page. The application has multiple rooms where users can enter their messages and after editing i wish to redirect to the same room where message was posted. I cannot use two primary keys inside a function and i feel like i am missing something. https://www.toptal.com/developers/hastebin/raw/zehakeyaki here is the code. Thank you for your time.
Sunken
Can somebody help me to fix this? ImportError: cannot import name 'ThreadSensitiveContext' from 'asgiref.sync'
Kirill
hi! have a problem in prod in admin django 4, 403 and "CSRF verification failed. Request aborted.". Works on dev server. I dont use SSL, dont override anything, cookie is set successfully, middleware is turned on in settings but i have no domain: access prod by ip. config: CSRF_COOKIE_AGE 31449600 CSRF_COOKIE_DOMAIN None CSRF_COOKIE_HTTPONLY False CSRF_COOKIE_NAME 'csrftoken' CSRF_COOKIE_PATH '/' CSRF_COOKIE_SAMESITE 'Lax' CSRF_COOKIE_SECURE False CSRF_FAILURE_VIEW 'django.views.csrf.csrf_failure' CSRF_HEADER_NAME 'HTTP_X_CSRFTOKEN' CSRF_TRUSTED_ORIGINS ['my ip'] CSRF_USE_SESSIONS False. any hints pls?
Kirill
Did your site use SSL (https)?
no, but i am planning to add in the future
Chaitanya
Try to use it. It could be the error. Letsencrypt provide free ssl certificate. It's easy to deploy. Try thier website for instructions for your web server
Kirill
thanks but it looks too complex: need to install snapd (which doesnt starts in ubuntu 20 for some reason because it uses systemd and systemd is not used by default), then need to install certbot, etc.. became too complex since django 2 to deploy without ssl
Kirill
worked with CSRF_TRUSTED_ORIGINS = ['http://' + IP + ':8000']
Dmitry
Hey, people! Is template inside a template a good idea? (somewhere it must be plain text, somewhere it's a plot in matplotlib, somewhere it's a test with ABC, etc). What is the best way to implement this thing in Django?
SuperN00b
hi guys , I am deploying a django app that include websocket, using nginx only , note that for testing I run server by manage.py scripts
SuperN00b
the problem I met now is that websocket can not connect
SuperN00b
and this is my nginx conf
SuperN00b
`server { # root folder of your application root /home/ubuntu/django-battleship/; listen 80; charset utf-8; client_max_body_size 100m; # place where logs will be stored; # folder and files have to be already located there, nginx will not create access_log /home/ubuntu/django-battleship/logs/nginx-access.log; error_log /home/ubuntu/django-battleship/logs/nginx-error.log; location / { proxy_pass http://localhost:8000; } location /ws/ { proxy_pass http://localhost:8000/ws/; } # static files folder, I assume they will be used location /static/ { alias /home/ubuntu/django-battleship/static/; } # media files folder location /media/ { alias /home/ubuntu/django-battleship/media/; } proxy_set_header Host $host; }`
Sai
For the channels read django official doc
SuperN00b
Use daphne
there is no way to avoid using some asgi support server friend ?
Sai
there is no way to avoid using some asgi support server friend ?
Didn't not understood. Can u more clear on this
SuperN00b
Didn't not understood. Can u more clear on this
nvm , as you said , I think I really need something like daphne
SuperN00b
try enabling http2 support
I’ll try it , thanks
Sai
I’ll try it , thanks
I tried this way but didn't work. Then I moved to Daphnr
SuperN00b
I tried this way but didn't work. Then I moved to Daphnr
thanks friend , I will dig some more on daphne
Брат
https://dpaste.org/SnpO
Брат
https://dpaste.org/SnpO
How do I set the field to logged-in user automatically once model was created?
Брат
Set default to true in your models
Nah, Im trying to set the field to current logged-in user
Брат
user2 should be equal to some user's username
Брат
which logged in
Брат
It is like you wanna add some friend, but you need to pick yourself too(your user), to be friends. Thereby, I wanna that field to be set automatically.
Mr Sourav
class userProfile(models.Model): person = models.ForeignKey(User, on_delete=models.CASCADE) bio = models.TextField(max_length=500, null=True, blank=True) Please tell me, by which query I can get this bio of user? This user model is django's default user model.
Mr Sourav
Id? Which id I've to pass?
Mr Sourav
user.id will return current user's bio?
DN
Id? Which id I've to pass?
The field u require..
DN
user.id will return current user's bio?
No . It will return only id i,e primary key
DN
Okay I'll try this
User.bio will give u that object's bio
DN
user = User.objects.get(id=pk) Bio = user.bio
Mr Sourav
https://pastebin.com/zkj06j9p
Mr Sourav
https://pastebin.com/zkj06j9p
Here is the code. And this is returning absolutely nothing...
DN
Here is the code. And this is returning absolutely nothing...
Bro ur model class name is not User it's userProfile, check it once
DN
Import models in ur views n then fire a query user = userProfile.objects.get(id=pk)
Mr Sourav
Bro ur model class name is not User it's userProfile, check it once
In that case query is returning the object according to id. Suppose a person's user.id ==3 and user profile.id==4. And another person has vice-versa. Then django is showing the object to the person whose user.id is 3, whose userprofile I'd is 3. It's not matching with the users. It's complicated to understand but please...
amirHosseinZibaei
How to serve media files in production through cpanel
Pavel
Hi everyone! I'm making a Django Rest Framework application with a JWT authentication with tokens stored in HttpOnly cookies. Authentication is performed via reading the access cookie. I'm using a dj-rest-auth library for this purpose, but I'm a little confused of the security aspect of such method. Knowing that having authentication data stored in cookies can be used to perform CSRF attack, how can one protect their web against such attacks for a specific case I've described above? All cookies are set to be SameSite=Lex. Do I need to also send X-CSRFTOKEN header obtained from the backend? That would mean that every request to the api will need to have that header. What should be the optimal setup having all those libraries?
Adjetey
Hello
Adjetey
Please am having a small issue
Adjetey
Django contact form not showing the sender's email
Nestor
quick question, what's the use of serializers fields in DRF if you can define what fields to serialize in Meta class?
luci._
Hello Goodnight. I am developing a small app that expects to receive between 200-400 visits a day and host about 100-300 users. It is a tutorial blog, the idea is that each user can upload between 1-6 photos. I want to deploy this project, but I don't know where. Any recommendations? I have seen ec2, gcloud, firebase, heroku, Lightsail. Sincerely, I look for the most economical option and that is easy to orchestrate the storage, bbdd and ci. I appreciate your help
luci._
oh excellent I did not know that option, do you know if it can hold docker?
luci._
thank you im going to try it.
Sp
Is there any people from kerala india who can teach me django and help me to do a project with individual assistance
Doragonsureiyā
Is there any people from kerala india who can teach me django and help me to do a project with individual assistance
Rule 🔟: Job posts are SPAM unless they meet the requirements. Read the rules for details.
Crygo
Is there a relationship between 3 models? For example models(forum,topic,post)Can I access like forumobj.topics.post_set_all?
Sivakanish
Guys does anyone know how to do crud operations In django can you please help me with code
Anshu
Guys does anyone know how to do crud operations In django can you please help me with code
There are multiple tutorials and blogs for the same, use those resources
Anshu
Bro can you share me a 🔗 link please
https://www.geeksforgeeks.org/django-crud-create-retrieve-update-delete-function-based-views/
fateme
I wrote an ajax function , to use in django admin where the user is creating .to populate the city field based on state field that select on drop down mood. But I cant absolutely find the element id of state field. can any one help me? ( state and city field have fk to the State and City model)
Naresh
How to redirect next page while data is insert in django
Naresh
It's not working