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
Could I use Django to create a fully functional employee scheduling system?

I'm thinking to use Django, React and PostgreSQL. I'm a newbie that just started working with Django (and coding in general) about half a year ago. I haven't done anything too crazy complex but I wanted to see if I could challenge myself to build an employee scheduler since it's something I could see really improving my uncle's life. My biggest question is, could I use Django for this? I know it's a powerful framework but I haven't really unlocked its full potential yet Here is the use case:

My uncle has to schedule hundreds of employees across 25\~ stores. He has to manually set schedules every month which is really painful as you might imagine since you have to ensure that every restaurant has enough staff at all times, employee time constraints and there are some floating managers that go where they are needed. I would love to be able to have a UI where my uncle can store employee info like their names, employee id, position, store, hours they can work, their pay rate, etc. I could see this as a microservice all on its own.

Another microservice can be restaurants' details which includes all the store hours

/r/django
https://redd.it/xmbidx
500 internal server error

I have jupyter notebook installed with conda which was done a few years ago. Just recently I've installed the latest version of python using pip and also installed jupyter notebook. When I use the terminal to run jupyter notebook I can open it but then I get a internal server error when trying to open the file. Is this because it conflicts with my existing jupyter notebook with conda? And if so how do I resolve this issue?

/r/JupyterNotebooks
https://redd.it/xizhr4
Best practice for an app with ML?

I'm working in project that uses ML for recommendation purposes. However, the ML part is implemented in a Fast API as another server. The problem is that since the ML part is in another app, the Django app must send request to this app and then retrieve it which causes a noticible performance delay.

Mind you, these requests are pretty frequent and are even worse in a deployed environment as the both apps are deployed seperatly.

My partner said that this is common in apps that utilize AI and is the best practic. However, I don't think this fits our case and introduces many issues that don't need to be solved. I think that we could just implement the whole in Django itself rather easily.

If you have had experience with a similar issue, I welcome your insight. What is really the best practice for project like this? Would it be better to just implement it in Django instead of using two separate apps?

/r/django
https://redd.it/xmtl92
Force the users to change the password before first login

Hi Guys,

I have a question about Flask, or better: about Flask-Security. I’m working on an app that should help to complete specific tasks as a team. I implemented Flask-Security-Too to handle login, logout, password change and very important to have certain user roles. However, users should be registered by admins only. The admin will set an initial password, that must be changed by the user before the first login. Admins will also be able to reset the password by changing it to a temporally one, which must then be changed by the user after it is used for login.

I’ve seen this concept in a lot of other apps and was wondering if it could be implemented with Flask/Flask-Security. And if yes, what would be the most practicable/secure way.

Any thoughts? :)

/r/flask
https://redd.it/xmxegk
Why django over asp.net core?

C# is a statically typed languages so you don’t really need to write tests to expose compile time issues in asp.net core whereas in django it is really necessary. Additionally the number of requests handled by asp.net core seems far superior than django (I found somewhere else a ratio of 10:6). So why do you all still use django?

I am looking for an honest opinions to present to my non-technical management that our decision to go with django over asp.net core is good.

We did go with django especially considering django admin panel, so we don’t need to write a lot of code but ask some of our stakeholders to complete a few things using django admin panel. This indeed decreased the delivery time. However now we found using different external tools the stakeholders could do the things still if we just provide them the database tables. Thank you.

/r/django
https://redd.it/xmpepd
ModuleNotFoundError: No module named 'Crypto' and more issues

Base Github I am using: bookwyrm-social/bookwyrm: Social reading and reviewing, decentralized with ActivityPub (github.com)

My Fork of team fork: cmorgan2016/bookwyrm-genres: Social reading and reviewing, decentralized with ActivityPub (github.com)

Note: I am struggling to get commit to work

Their tutorial: [Developer Environment (
joinbookwyrm.com)](https://docs.joinbookwyrm.com/install-dev.html)

What I am using: Git Bash and Virtual Studio Code

what happen when I debug:

crbug/1173575, non-JS module files deprecated. chromewebdata/(index)꞉6564:22:6789

https://preview.redd.it/hivvzp9fu0q91.png?width=730&format=png&auto=webp&s=3e58397c0085dfdf03e96b2d7569765134977ed6

I'm getting this error when I run $ python [manage.py](https://manage.py) makemigrations --merge and I have run

pip install Crypto
pip install pycrypto
pip install pycryptodome

When I run ./bw-dev build

+ case "$CMD" in
+ docker-compose build
Error response from daemon: i/o timeout: driver not connecting

When I run ./bw-dev setup

+ case "$CMD" in
+ migrate
+ runweb python manage.py migrate
+ docker-compose run --rm web python manage.py migrate
Error response from daemon: i/o timeout

When I run ./bw-dev up

+ case "$CMD" in
+ docker-compose up

/r/djangolearning
https://redd.it/xnqbjw
is installing jupyterthemes safe?

Hi there,

Just a curiosity - I get extreme strain and headaches from looking at monitors for to long so I installed juptyerthemes to enable darkmode since its not already a thing. Everything I could find didnt give a definite answer as to whether it was malicious or not...

/r/JupyterNotebooks
https://redd.it/xfjkee
Edit DB

Best approach to edit DB in production? For instance in case of a new group of users to register? I usually write a .py file using Alembic, but maybe there is a better approach. Writing raw SQL is not great I think, as I have many columns using SQLAlchemy's "default" param, so they would not be automatically set by raw SQL queries.

/r/flask
https://redd.it/xnkwyz
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/xn81cz
Monday Daily Thread: Project ideas!

Comment any project ideas beginner or advanced in this thread for others to give a try! If you complete one make sure to reply to the comment with how you found it and attach some source code! If you're looking for project ideas, you might be interested in checking out Al Sweigart's, "The Big Book of Small Python Projects" which provides a list of projects and the code to make them work.

/r/Python
https://redd.it/xo37yn
D Simple Questions Thread

Please post your questions here instead of creating a new thread. Encourage others who create new posts for questions to post here instead!

Thread will stay alive until next one so keep posting after the date in the title.

Thanks to everyone for answering questions in the previous thread!

/r/MachineLearning
https://redd.it/xnpn0j
Where is self.client inherited from?

The [official documentation](https://docs.djangoproject.com/en/4.1/topics/testing/tools/#default-test-client) states:

> Every test case in a django.test.*TestCase instance has access to an instance of a Django test client. This client can be accessed as self.client.

And sure enough, this works. But:

from django.test import TestCase

dir(TestCase)

returns no method called "client".

Where is self.client inherited from?

/r/djangolearning
https://redd.it/xoeqv0
validate value calculated from another field

i need to validate a field in django admin.

the field is calculated based upon a value of another field.

i've tried several solutions but none could work like i intended, for example:

1. i calculated the value before saving and then raise a validation error but i didn't manage to make the error pop inside the form (as a red string like the validator already build inside django)
2. i tried to use a validator already build in but i didn't know how to reference the other field inside the validator. ** this would be the ideal solution since its the cleanest**
3. i tried to manipulate the admin form to validate the value but the value is not yet calculated in there as far as i know. in this attempt i also tried to make the field of interest ( the one that get calculated) as a property using a decorator so it would be calculated before validation

what i am trying to achieve is to create a Trade model where i insert the amount of capital to invest and the risk per share i want to take. the idea come from this blog. basically i'm trying to replicate the functionality of the Money

/r/djangolearning
https://redd.it/xohm8s
How I deploy my bootstrapped Python webapp with 150k monthly users

I am a one-man show building a web-based software product. Some quick facts about my app:

Written in Python Flask
150k visitors per month
15k registered users
3k US$ revenue per month
70 requests per second at peak-time

This is a technical post looking at the infrastructure that runs my app with a focus on how I deploy it.

## Summary

I use 2 VPS (virtual private servers) running on DigitalOcean
The database is Postgres and is fully managed by DigitalOcean
I use a blue-green deployment
Deployment is done via `git` and `ssh`.
No CI/CD
No containers
Absolutely no Kubernetes

I am a strong advocate of using "boring technology". I am also the only developer of the app, which makes many things simpler.

## The application infrastructure

The app is a CRUD monolith that is deployed as one artefact. I use nginx and gunicorn to serve the app.

The app runs on 2 virtual private servers, one of which is the production server, the other of which is the staging server. During deployment, they switch roles. This is a so-called blue-green deployment, more on that later.

I'm using a DigitalOcean droplet with 8 shared CPUs, 16GB of memory and 80 GB of storage for each server.

/r/Python
https://redd.it/xobba8
Does some CSS work differently in Django?

I have this CSS. It works fine when I use it for a regular site from just plain HTML and CSS. When I use this with my Django template it acts differently. What I expect to happen is the navigation bar will be flush with the top of the screen. This happens with the plain HTML site. In Django, however there is a gap at the top where you can see the body of the page.

`* {`

`-webkit-box-sizing: border-box;`

`-moz-box-sizing: border-box;`

`box-sizing: border-box;`

`}`

​

`body {`

`margin-top: 90px;`

`background-color: lightgray;`

`}`

​

`.navi {`

`position: fixed;`

`height: 45px;`

`top: 0;`

`right: 0;`

`left: 0;`

`background-color: black;`

`color: white;`

`padding: 5px`

`}`

​

`.navi-link {`

`color: white;`

`text-decoration: none;`

`padding: 5px;`

`}`

Edit: Here is the HTML

In Django:

`{% load static %}`


`<!DOCTYPE html>`
`<html lang="en">`
`<head>`
`<meta charset="UTF-8">`
`<link rel="stylesheet" href="{% static 'css/style.css' %}">`
`</head>`
`<body>`
`<header>`
`{% include 'navi.html' %}`
`</header>`
`{% block content %}`


`{% endblock %}`


`</body>`
`</html>`

Regular HTML:

`<!DOCTYPE html>`

`<html lange='en'>`

`<head>`

`<meta charset='UTF-8'>`

`<title>Practice CSS</title>`

`<link rel='stylesheet' href='style.css'>`

`</head>`

`<body>`

`<header class='navi'>`



`<a class='navi-link' href='index.html'>Home</a>`

&#x200B;

`</header>`



`<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo

/r/djangolearning
https://redd.it/xox2gy
Tuesday Daily Thread: Advanced questions

Have some burning questions on advanced Python topics? Use this thread to ask more advanced questions related to Python.

If your question is a beginner question we hold a beginner Daily Thread tomorrow (Wednesday) where you can ask any question! We may remove questions here and ask you to resubmit tomorrow.

This thread may be fairly low volume in replies, if you don't receive a response we recommend looking at r/LearnPython or joining the Python Discord server at https://discord.gg/python where you stand a better chance of receiving a response.

/r/Python
https://redd.it/xp0c2v
How to modify POST data before it gets validated without throwing a ValueError exception?

I am trying to convert a date that is created by a frontend datetime library to a iso formatted date.

I do this using python's strptime function, which throws an exception if it can't format the date. I do this in my view and Django shows an exception page in that case, but I want Django to throw a normal ValidationError that can be seen in the frontend.

I tried writing a clean_date() function in my form to modify the date but Django's DateTimeField validator runs before clean_date() and so my code is never run.

/r/django
https://redd.it/xpn1bw