Maxim
I meant scanned pdf
what does this have to do with Django? do you know what this group is?
….
Hello Please I am using django-allauth headless for my authentication endpoints. Anytime I send a post request using postman to the _allauth/browser/v1/auth/login endpoint. i get a 403 forbidden saying CSRF cookie not set. Please how can I solve this
Doragonsureiyā
Anybody knows pdf editing (private pdf)
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.
Chillguy
Where can i find best django and drf courses? (free or paid)
Mobin
I'm having a problem with Django response class StreamingHttpResponse. When I return a generator as response using StreamingHttpResponse and make a request I excepted to retrieve each data block one by one, instead of that i retrieve the full data at once when the generator loop has finished. My Django View: def gen_message(msg): return 'data: {}\n\n'.format(msg) def iterator(): for i in range(100): yield gen_message('iteration ' + str(i)) print(i) time.sleep(0.1) class test_stream(APIView): def post(self, request): stream = iterator() response = StreamingHttpResponse(stream, status=200, content_type='text/event-stream') response['Cache-Control'] = 'no-cache' return response And I make the request like that: r = requests.post('https://******/test_stream/', stream=True) for line in r.iter_lines(): if line: decoded_line = line.decode('utf-8') print(decoded_line) When I see the output of the Django server I can see the print every 0.1 seconds. But the response in the second code only shows when the for loop is finished. Am I misunderstanding the StreamingHttpResponse class or the request class or is there another problem? plus iam using Daphne as my ASGI server
Mobin
I'm having a problem with Django response class StreamingHttpResponse. When I return a generator as response using StreamingHttpResponse and make a request I excepted to retrieve each data block one by one, instead of that i retrieve the full data at once when the generator loop has finished. My Django View: def gen_message(msg): return 'data: {}\n\n'.format(msg) def iterator(): for i in range(100): yield gen_message('iteration ' + str(i)) print(i) time.sleep(0.1) class test_stream(APIView): def post(self, request): stream = iterator() response = StreamingHttpResponse(stream, status=200, content_type='text/event-stream') response['Cache-Control'] = 'no-cache' return response And I make the request like that: r = requests.post('https://******/test_stream/', stream=True) for line in r.iter_lines(): if line: decoded_line = line.decode('utf-8') print(decoded_line) When I see the output of the Django server I can see the print every 0.1 seconds. But the response in the second code only shows when the for loop is finished. Am I misunderstanding the StreamingHttpResponse class or the request class or is there another problem? plus iam using Daphne as my ASGI server
but if I implement it with FastAPI or flask it works
Ahmad
TypeError: OAuth2Client.init() got multiple values for argument 'scope_delimiter' how solve this
شهرزاد محمد
I'm having a problem with Django response class StreamingHttpResponse. When I return a generator as response using StreamingHttpResponse and make a request I excepted to retrieve each data block one by one, instead of that i retrieve the full data at once when the generator loop has finished. My Django View: def gen_message(msg): return 'data: {}\n\n'.format(msg) def iterator(): for i in range(100): yield gen_message('iteration ' + str(i)) print(i) time.sleep(0.1) class test_stream(APIView): def post(self, request): stream = iterator() response = StreamingHttpResponse(stream, status=200, content_type='text/event-stream') response['Cache-Control'] = 'no-cache' return response And I make the request like that: r = requests.post('https://******/test_stream/', stream=True) for line in r.iter_lines(): if line: decoded_line = line.decode('utf-8') print(decoded_line) When I see the output of the Django server I can see the print every 0.1 seconds. But the response in the second code only shows when the for loop is finished. Am I misunderstanding the StreamingHttpResponse class or the request class or is there another problem? plus iam using Daphne as my ASGI server
I tried the same code and found that the issue is with the requests library. I tested this code, and it worked correctly: import httpx url = 'https://******/test_stream/' with httpx.stream("POST", url) as response: for line in response.iter_lines(): if line: print(line)
Hadi
I tried the same code and found that the issue is with the requests library. I tested this code, and it worked correctly: import httpx url = 'https://******/test_stream/' with httpx.stream("POST", url) as response: for line in response.iter_lines(): if line: print(line)
If you handle the errors, the code will be better: import httpx url = 'https://**/test_stream/' try:     with httpx.stream("POST", url) as response:         response.raise_for_status()         for line in response.iter_lines():             if line:                 print(line) except httpx.HTTPStatusError as e:     print(f"HTTP Error: {e}") except httpx.RequestError as e:     print(f"Request Error: {e}")
Eric
If you handle the errors, the code will be better: import httpx url = 'https://**/test_stream/' try:     with httpx.stream("POST", url) as response:         response.raise_for_status()         for line in response.iter_lines():             if line:                 print(line) except httpx.HTTPStatusError as e:     print(f"HTTP Error: {e}") except httpx.RequestError as e:     print(f"Request Error: {e}")
For completeness shouldn't you handle all other errors, if the exception is not a HTTPStatusError or RequestError?
~~~
Hi all, I am new to django, i studied the basics and also build a blog application. Now i am creating a ecommerce aplication...can anyone suggest best resource to study user authentication for the system..other than the documentation.
Hadi
For completeness shouldn't you handle all other errors, if the exception is not a HTTPStatusError or RequestError?
Yeah you're right. We can cover other exceptions by adding Exceptions block: import httpx url = 'https://******/test_stream/' try:     with httpx.stream("POST", url) as response:         response.raise_for_status()          for line in response.iter_lines():             if line:                 print(line) except httpx.HTTPStatusError as e:     print(f"HTTP Error: {e}") except httpx.RequestError as e:     print(f"Request Error: {e}") except Exception as e:     print(f"Unexpected Error: {e}")
Pablo
Hi all, I am new to django, i studied the basics and also build a blog application. Now i am creating a ecommerce aplication...can anyone suggest best resource to study user authentication for the system..other than the documentation.
You can check out this tutorial on youtube. It covers user registration, login, and password reset features: https://youtu.be/_9K0MTBOKNs?si=c-a7rz4OGCqHKD3J
Sivaraj
Is there any feature difference for using mysql and postgres in Django?
Mirco
cj
Is there any feature difference for using mysql and postgres in Django?
you can read this: https://docs.djangoproject.com/en/5.1/ref/databases/
Sivaraj
You have more features and power with postgres
Can you share any docs regarding the feature comparison ?
Mobin
I tried the same code and found that the issue is with the requests library. I tested this code, and it worked correctly: import httpx url = 'https://******/test_stream/' with httpx.stream("POST", url) as response: for line in response.iter_lines(): if line: print(line)
it works with flask but not with django, it waits for the generator to finish and then returns the data all at once def stream(request: HttpRequest): print(request.method.upper()) def large_data(): for i in range(10): yield f"data: {i}\n\n" time.sleep(0.5) print(f"data: {i}") yield "data: end\n\n" response = StreamingHttpResponse(large_data(), content_type="text/event-stream") response.headers['Cache-Control'] = 'no-cache' return response does it have something to do with the middlewares? maybe some middleware in the middle is causing this. # settings.py MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ]
Charly
You mean how we learned it?
Mobin
they are similar to function based views, in function based when you wanna write code for post or get requests you have to use a if statement to check if is a get or post but in class based you implement the get and post methods and when a request comes in django automatically calls those methods based on the request.method
mbk
Hey I want to create a dynamic cron using celery A cron that schedules dynamic basis on time If the time is updated it must reschedule to updated time and cancel the previous request of old time How can I achive it ?
Pablo
You will need to make use of celery to run the task and celery beat to schedule it. By default when a change in schedule of a task occurs, it restarts celery beat
mbk
Celery beats sounds good to me also
mbk
But I have not implemented it yet anyhow If there are any documentation that could help,please share it
Pablo
But I have not implemented it yet anyhow If there are any documentation that could help,please share it
Yes there is a documentation for Django celery beat. You can check it out here: https://django-celery-beat.readthedocs.io/en/latest/
❥︎ 𝓔𝓻𝓯𝓪𝓷
Hello, I'm using JWT. For refreshing the token, I want to send the request using cookies instead of posting. However, the frontend team is asking me to change it and receive it through headers. Which method is safer and better?
mohamad
Hello , If there are two domains the first one for backend django and the second one to react and i want to use django auth but i cant see in cookies of browser session or csrf what is the reason ?
شهرزاد محمد
Hello , If there are two domains the first one for backend django and the second one to react and i want to use django auth but i cant see in cookies of browser session or csrf what is the reason ?
You need to make in settings.py CSRF_COOKIE_SAMESITE = 'None' SESSION_COOKIE_SAMESITE = 'None but this is less secure.
T
Hi, i want to implement django redis caching. So what is the best approach in caching depends on multiple related models?
Mirco
Hi, i want to implement django redis caching. So what is the best approach in caching depends on multiple related models?
latest django supports it without the need of installing external lib like django-redis so it's very simple
hamid
Hi guys I have an ImageField in django admin I want it to have a crop ability for image while uploading How could I do that?
hamid
you have to use Pillow
I know that I need more help
KAKASHI
Hi guys I have an ImageField in django admin I want it to have a crop ability for image while uploading How could I do that?
In your Django admin, you need to enable the cropping feature for the image field. You can do this by using the ImageCroppingMixin from django-image-cropping. Here’s an example of how to do it: from django.contrib import admin from image_cropping import ImageCroppingMixin from .models import MyModel class MyModelAdmin(ImageCroppingMixin, admin.ModelAdmin): list_display = ['image'] # Include image field in the list view # You can also customize other admin options here admin.site.register(MyModel, MyModelAdmin)
Mehda
hello evry one i have question with drf i have a class of user and child class of doctors , admin , patient i dont now how to implement this in drf if i use generalisation and specialisation or just use group and permissions
crypto
Any tutorial here on YouTube to learn Django?
Charly
Any tutorial here on YouTube to learn Django?
yeah, have you used the search on youtube you can sort by views to get the most popular
Siuuuu!!
Any tutorial here on YouTube to learn Django?
Bugbytes, dennisuvy, calebcury Search these on YT
Karan
Anyone has idea about django Channels with rest apis integration with react app ? Any good source to read about their integrations
Lee@2731#
Hi i have django .. project i implemented most complex logic and i render page.. but it's taken long time ...how to we fix and ...any tool for rendering page debugging tool
Pablo
Hi i have django .. project i implemented most complex logic and i render page.. but it's taken long time ...how to we fix and ...any tool for rendering page debugging tool
You will need to provide us more context as to what 'complex logic' might mean but a solution would be to optimize your db queries and perhaps implement caching for speed
Lee@2731#
You will need to provide us more context as to what 'complex logic' might mean but a solution would be to optimize your db queries and perhaps implement caching for speed
But already i implemented select_related() and index also used . Issues may i think templates tags use that template tag function also some more logical functions .
kim
Where can I host django for free?
Pablo
Thanks
If you need a tutorial, you can watch this: https://youtu.be/qbDi-v2NZgo?si=87JJBxdnFw10mebq
Charly
Liara.ir
Please avoid sharing Links that are not in English
william
Hello good evening, excuse me I'm creating a web application, and I'm going in the part of groups and permissions, I know that django has a function of groups and permissions at the model level, but I was something to manage permissions to the templates, I mean that the user can only view parts of the website depending on his privileges Any resources, blogs, tutorials that you could share with me
Omadbek
Pablo
Hello good evening, excuse me I'm creating a web application, and I'm going in the part of groups and permissions, I know that django has a function of groups and permissions at the model level, but I was something to manage permissions to the templates, I mean that the user can only view parts of the website depending on his privileges Any resources, blogs, tutorials that you could share with me
You can make use of the groups setup as you have said. You can use a simple if statement to check if the user is part of a said group before rendering out the web page, else if not display and error message or redirect then to a different view Or if you want to restrict viewing to certain parts of the template, the same logic applies where you can use Django templating if statements to render out certain parts of the html depending on a condition (user part of a group)
𝚆𝚘𝚛𝚕𝚍𝚕𝚎𝚜𝚜
Guys to make a good django resume , is it necessary for our projects to have a good frontend too? Recently i made a project with strong backend yet simple frontend (https://theartificialflower.pythonanywhere.com) So yet again , is good frontend necessary for django projects? 🤔 And I'm sorry if it seems unrelated
Kasem
Hello everyone, is it feasible to pull tweets from X platforms to analysis? Is there a free plan for this purpose? If there anyone test that using Django could give me advice?
brandnew
Hello, Can anyone share me a website where I can learn and master django? Thanks in advance.
Doragonsureiyā
Looking for Django tutorials? you can follow these three recommended ones: * Official documentation and tutorial * Tutorial from MDN * Tutorial from django-girls
Java
Hello, Can anyone share me a website where I can learn and master django? Thanks in advance.
You can apply to join Django Girls this year! I'll be coaching them from the introduction until we build a complete web application using Django.
Nasrullah
Guys, does anybody have worked with django uuid? Is it suitable to create certificate verification system?
Doragonsureiyā
Hello everyone, is it feasible to pull tweets from X platforms to analysis? Is there a free plan for this purpose? If there anyone test that using Django could give me advice?
Adding the word Django to your Off-Topic question doesn't magically turn it to a Django specific question, so delete your question here and move to the @PythonOfftopic group and ask there.
Pablo
Guys, does anybody have worked with django uuid? Is it suitable to create certificate verification system?
I have done so before so it’s decent I would say. Each certificate will have a unique uuid so it’s easier to find each individual one and differentiate