Python Daily
2.57K subscribers
1.48K photos
53 videos
2 files
38.9K links
Daily Python News
Question, Tips and Tricks, Best Practices on Python Programming Language
Find more reddit channels over at @r_channels
Download Telegram
Django (Both in backend and frontend) or Django Rest Framework + React?

I would like to develop a website (like Zillow) by myself and I don't know if it would be easier to do it using only Django (with Django templates and vanilla Javascript for functionality and interactivity) or Django Rest Framework and React.

I have experience in React but I do not enjoy writing a separate backend and frontend. Also I don't like React that much. Is it possible, easier and better for only one dev to use only Django for a project like that?

/r/django
https://redd.it/10ai8h7
Django AWS S3 image files working locally but not in production

I'm creating a website with a blog that allows users to upload their own profile pictures, and this works locally. However, in deployment on OpenShift it returns an error ' The requested resource was not found on this server.'

​

My code in settings:

​

MEDIAROOT = os.path.join(BASEDIR, 'media')
MEDIAURL = '/media/'

AWS
ACCESSKEYID = 'xxx'
AWSSECRETACCESSKEY = 'xxx'
AWS
STORAGEBUCKETNAME = 'xxx'
AWSS3REGIONNAME = 'eu-west-2'
AWS
S3ADDRESSINGSTYLE = "virtual"
AWSS3SIGNATUREVERSION = 's3v4'

AWS
S3FILEOVERWRITE = False
AWSDEFAULTACL = None
DEFAULTFILESTORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

Locally, the link to an example image is: https://personal-portfolio-website-files.s3.amazonaws.com/profile\_pics/dog.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIA5HK62K4UKN4EU6UQ%2F20230111%2Feu-west-2%2Fs3%2Faws4\_request&X-Amz-Date=20230111T120246Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&X-Amz-Signature=7ca52e78c5c266d18d24d4fc1bdb6ddb22267d06c09ba3eae1f6853fba7f1b91

​

Whereas on OpenShift, it's: http://personal-portfolio-web-personal-portfolio.apps.openshift.cs.cf.ac.uk/media/profile\_pics/dog.jpg

​

Does anyone know what's causing this?

I've tried changing all the permissions of my bucket to allow everything.

/r/django
https://redd.it/1093i83
Django Knox login endpoint not working

I used files from "https://github.com/Omkar0231/Django-Login-API" with no change. But, the login request from Postman is resulting in error, "detail": "JSON parse error - Expecting value: line 1 column 1 (char 0)", while the terminal shows "Bad request...".

The source code developer in above git also explained it in a video, "https://www.youtube.com/watch?v=6d0fiPj0dsA", however, in video everything seems to be working as expected.

Whatever I understood from Googling, I thought that a bearer token is to be included in the login request as header. But I don't know where to find the bearer token in my Django app. However, in the video, the original author/developer did not include any such header token for the login request from Postman.

Please help me figure out the issue.

/r/django
https://redd.it/108yj85
Sunday Daily Thread: What's everyone working on this week?

Tell /r/python what you're working on this week! You can be bragging, grousing, sharing your passion, or explaining your pain. Talk about your current project or your pet project; whatever you want to share.

/r/Python
https://redd.it/10c4t91
What are people using to organize virtual environments these days?

Thinking multiple Python versions and packages

Is Anaconda still a go to? Are there any better options in circulation that I could look into?

/r/Python
https://redd.it/10bxkjp
Total beginner - Could Python be interesting for sales?

Hi there kind Python people.

Thank you for taking the time to read my question! It might be different to what normally gets posted in this sub. It's not about programming, but about career choices.

I am a 28 year old with a masters degree in Communication Sciences. Ever since finishing my studies I have been very interested in programming, AI, big data... Yet for the last years I preferred a life of travelling around and parties instead of really sharpening my skills. The time has really come for me to dedicate myself. I have taken up routines and discipline, and I have an ambitious mindset.

At this moment I am about to start a sales job (wholesale in medical disposables) in a very small but growth-oriented company. It is far from my dream job, but I want to view this as a very important step on my ladder. I want to learn a lot.

I believe there would be an awful lot to learn before it even could become useful, but as far as I understand what this language does it could come in handy for creating and managing databases of (potential) customers, sales histories, keeping track of inventory

/r/Python
https://redd.it/10c4o15
Check out AWESOME PANEL SHARING - An easy to use sharing service for Panel data apps

In 2022 Pyodide and PyScript paved the way for Python in the Browser. On top of that, the data app framework Panel made it easy to panel convert your data app to run in the browser only.

On top of that I created AWESOME PANEL SHARING that is a easy to use sharing service for Panel data apps.

Check out the growing Gallery of inspirational examples.

Awesome Panel Sharing Gallery

Or share your data app with the world.

https://reddit.com/link/10cbt17/video/caafvw9595ca1/player

/r/Python
https://redd.it/10cbt17
(Maybe) Everything You'll Ever Need to Know about Python Imports and Project Structure

It isn’t that hard, but it is a well-kept secret. And for good reason. I’ve had a draft of this article in my head for months, but it wasn’t until I started using Poetry that I found a method I could explain in a two-minute read.

(Maybe) Everything You'll Ever Need to Know About Python Imports and Project Structure (foundationsafety.com)

/r/Python
https://redd.it/10c49jo
Web based GUI Application

I know that this question has been asked by many so Please bear me.
What is the best way to go about making web based GUIs using Python as backend ?
I don’t know anything about HTML CSS or JavaScript.
If you can suggest any designer tool that will be helpful Thanks

/r/flask
https://redd.it/10cfufj
Discord Bot pretending to be human using Chat GPT

Python script for a Discord bot that uses Chat GPT to generate responses for a conversation between multiple discord users.

The bot can converse in a conversation distinguishing between different people and responding like a friendly discord user. It understands the distinction between being involved in conversation and not being included.

These features only partially work, with the bot easily being able to be taken out of the immersion of being a "discord user". However, it was an interesting experiment to test the limits of GPT using the limited functionality we're currently available to. I believe it would definitely be possible to make a very convincing human! Hopefully API for Chat GPT will be released in the near future.

GitHub Link: https://github.com/karkin2002/Chat-GPT-Discord-Bot

Example conversations:

https://preview.redd.it/zk7ap6a9i7ca1.png?width=2085&format=png&auto=webp&v=enabled&s=a6d975e72e22323e115b19ad25a4da9d8b1004c6

https://preview.redd.it/dmdhmrpfi7ca1.png?width=2048&format=png&auto=webp&v=enabled&s=24102d01745ef3bfa3704e32750b5a9cfa3d216b

https://preview.redd.it/kqypicfvi7ca1.png?width=1657&format=png&auto=webp&v=enabled&s=5eb908593aa8b2a5b93e029bb46bd9756c8fd0d4

Example of distinguishing between being in conversation and not. For this test I made the bot respond with "N/A" if it thought it wasn't included in the conversation ("Friend" is the Discord bots name, "Kiwi" is another users name):

https://preview.redd.it/4sxdyhkuh7ca1.png?width=1116&format=png&auto=webp&v=enabled&s=91ba5271894d387b9d1d0bd941b7133fba562906

/r/Python
https://redd.it/10cjm62
Activities to keep in touch with python programming

Hello Everyone, I am a working professional(chip designer), I just finished the python course (Udemy) and gained fair knowledge. I have already used the knowledge gained to automate some of the reports review in the current company and have also started doing few simple projects for university students. Could you guys please suggest me some activities/habits to keep in touch with the python programing and explore much more? . Appreciate the help in advance.

/r/Python
https://redd.it/10chz9y
Yellowpage scraper powered by Python

Hey everyone,

I've been working on a web scraping project using Python to extract data from YellowPage and I wanted to share my experience and some tips for anyone else looking to do the same.

First, I used the popular library BeautifulSoup and Playwright to navigate and automate the website. The script asks user to enter a business name, location and number of pages to scrape and save it into an excel database accordingly. It extracts all the necessary data including emails as well. I feel I used lots of try and except clause, if someone has better approach them please free to share.

Another thing to watch out for is that the website structure can change frequently, so it's important to regularly check and update your code accordingly.

Overall, it was a fun and challenging project that taught me a lot about web scraping and working with dynamic websites.

Let me know if you have any questions or tips of your own to share!

/r/Python
https://redd.it/10cc17r
send a list of ids using ajax

i am trying to send a list of ids which are collected from the selected checkboxes in django template to django views using ajax as below,but doesn't seems to work.what could be wrong.i suspect the url part.

<script>
$(document).ready(function(){
$('.bulk_delete').click(function(){
if(confirm("Sure you want to delete?")){
var id=[];

var csrf=$('input[name=csrfmiddlewaretoken]').val();
$(':checkbox:checked').each(function(i){
id[i]=$(this).val()
})


/r/djangolearning
https://redd.it/10cfl7m
Can you explain to me how I can track and log the IP addresses and actions of every user who visits my website. My website is using Django cookie cutter, Sentry and Traefik.

Thank you.

/r/djangolearning
https://redd.it/10c3wmt
Hiding or showing fields based on a radio button click

I have a Django project I'm working on. I'm pretty new to Django, and even more so to CSS, HTML, HTMX. We are using Django-tweaks (which I think contains htmx?) and generating web pages for our project. I have a form where if you click on a radio button called risk\_area, it will hide or show two other fields. Those fields are called email and whatsapp. For all of my efforts, trying javascript, jquery, etc, it doesn't work. It runs the function showhide() (bottom of html file in script tags) on page load. It doesn't run it when I click on the radio buttons.


So my first question is.. using Django, htmx, tweaks, what is the cleanest solution to doing this? I could do views/forms approach to try to hide show the two fields, but this seems overkill when you just want to adjust two fields hiding or showing them. The fields are visible from the get go.


My 2nd question, assuming this is the way to go is why doesn't this javascript work?
`<script>`
    `window.onload = function () {`
`function showHideEmailWhatsapp() {`
`var riskarea =

/r/djangolearning
https://redd.it/10c6vjw
Djoser customization

I am using djoser for user registration but I want that some user will bypass the email verification

/r/djangolearning
https://redd.it/10bfzs7
Separate into spaces for users

Hi everyone, I am building a CRM using Django and deploying on Heroku. I am trying to understand what is the best practice for such a project. Basically I have customers and I create a space for them in which they can have users. Should I deploy a new project for each space that has its own webserver/database etc or should I have only one server with one database and just add a field "space" to the models? Seems a bit more dangerous in terms of security to me. And in this case should I have a separate table for each model per space or use only one table for each model and add a field as mentioned above?

/r/django
https://redd.it/10crpk6
Custom User Model - Login with email address and password for production use

How can I ensure that users can log in to the website with just an email address and password without an additional package?


For this I have already created a Custom User Model and changed AUTH_USER_MODEL:


models.py:

from django.contrib.auth.models import AbstractUser
from django.db import models
from django.utils.translation import gettextlazy as


class User(AbstractUser):
username = None
firstname = None
last
name = None
name = models.CharField(maxlength=150, blank=True)
email = models.EmailField(
("email address"), unique=True)

USERNAMEFIELD = "email"
REQUIRED
FIELDS =

settings.py:

AUTHUSERMODEL = "users.User"

There is a "Customizing authentication in Django" page on the Django website. There is an example at the end. But unfortunately there is also the following:


"not intended to be copied directly into projects for

/r/django
https://redd.it/10csae9
How to update data on a page without hitting API repeatedly?

Hi there, I have a project up and running which merges multiple pdf files into a single pdf file. The backend is in Django REST and Frontend is in Angular.

I have a merge log page showing all the ongoing or finished merge processes. It also has a percent complete column. Which only updates when the API is hit again.

I want to update the value of percent complete, without repeatedly hitting the API.

If I hit the same API at an interval of 1 second it will always show the latest data.

But is there any other way to achieve this?

/r/django
https://redd.it/10chrgo