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 site ready - but having trouble deploying in azure as web app or docker (inexperienced)

Hey y’all! Been working on a project and ready to drop the MVP on azure for UAT. But even though I’m azure fundamentals certified I am lacking in the deployment department and can’t quite get my azure web app up and clearing a 200 status code. Looking for help or even a recommendation for experienced help to get me familiar with the process.

Here’s where I’m at:
1. Django project with 2 apps, email and Postgres DB, all working in dev
2. Have a “deployment.py” file that is referenced if os.environ() finds an azure host name, otherwise debug version of settings.py is used
3. Deployed the app via GitHub repo connected to azure. In the deployment logs I get a warning that “Django must be in the requirements.py file” but it is. No other errors seen
4. When accessing the webpage using the azure temporary url I get a 504 error.
5. I can’t troubleshoot much further since I can’t find where other logs are located and the documentation I have found is outdated and doesn’t match the current azure UI

Any help or leads for troubleshooting are appreciated! Please feel free to ask for more info if I haven’t provided it!

/r/djangolearning
https://redd.it/1f07rqp
How to schedule a daily recurring function?

Hello everyone

So I built a basic backend and was wondering - how can I implement a function that has to run for example every day at 1pm?

Is there a classic way in Flask to do this?

Thank you very much!

/r/flask
https://redd.it/1f097gr
Doing testing in flask application.

Hi I am build an web application in flask using flask sqlalchemy and flask login for now.

Here is my conftest.pyfile

from app import createapp, db
from config import TestConfig
from flask
login import FlaskLoginClient
import pytest

@pytest.fixture(scope="session")
def app():
app = createapp(TestConfig)
app.test
clientclass = FlaskLoginClient

with app.app
context():
db.createall()

yield app

@pytest.fixture(scope="session")
def client(app):
return app.test
client()


here is my test_auth.py

def testsignupget(client):
res = client.get("/auth/signup")
assert b"<h2>Register Form</h2>" in res.data

def testsignuppost(client, app):
res = client.post("/auth/signup", data={


/r/flask
https://redd.it/1f0dak2
flash message.. show only 1 at a time.

how can I clear the current flash message before showing another.
I don't want to have a list of them show on the screen.




this is my code for show the messages

<footer class="mt-auto fixed-bottom">
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
{% for category, message in messages %}
{% if category == 'message' %}
<div class="alert alert-warning" role="alert">
{% else %}
<div class="alert alert-{{ category }}" role="alert">
{% endif %}
{{ message }}
</div>
{% endfor %}
{% endif %}
{% endwith %}
</footer>

/r/flask
https://redd.it/1ezde6j
Sunday Daily Thread: What's everyone working on this week?

# Weekly Thread: What's Everyone Working On This Week? 🛠️

Hello /r/Python! It's time to share what you've been working on! Whether it's a work-in-progress, a completed masterpiece, or just a rough idea, let us know what you're up to!

## How it Works:

1. Show & Tell: Share your current projects, completed works, or future ideas.
2. Discuss: Get feedback, find collaborators, or just chat about your project.
3. Inspire: Your project might inspire someone else, just as you might get inspired here.

## Guidelines:

Feel free to include as many details as you'd like. Code snippets, screenshots, and links are all welcome.
Whether it's your job, your hobby, or your passion project, all Python-related work is welcome here.

## Example Shares:

1. Machine Learning Model: Working on a ML model to predict stock prices. Just cracked a 90% accuracy rate!
2. Web Scraping: Built a script to scrape and analyze news articles. It's helped me understand media bias better.
3. Automation: Automated my home lighting with Python and Raspberry Pi. My life has never been easier!

Let's build and grow together! Share your journey and learn from others. Happy coding! 🌟

/r/Python
https://redd.it/1f0jb7c
Looking for a Job Urgently.

Hey guys, i know this is not the place for this and i know its a long shot, but i think it is worth a shot.

my name is Goodluck, 20 years old.

i recently wrote my final exams in college, so i'm almost a college graduate in Computer science. i need a job as soon as possible. I'm proficient in python and can build flask apps. i am a fast learner, so the things i don't know, i can pick up on the job without being a burden or slowing down the workflow. i know some people would advice to get an official job, but i haven't been lucky enough to get one. Most of the ones i've seen on twitter were either closed or just scams to get me to create an account with the job application service. I've applied for a few and i got rejected in all.

I'm looking for a python backend entry/intern role. I've never really worked in a real life industry since i mostly learnt from tutorials on Youtube and torrent courses, but i know i can handle an intern role. I don't mind working as an assistant to someone and i don't

/r/flask
https://redd.it/1ezok6c
How to elegantly use pydantic to parse YAML files containing rust enum types ?

I have been working on how to convert YAML containing enum defined by Rust to Pydantic recently, and finally I have the following solution.

from enum import Enum, IntEnum
from typing import Any, Union

from pydantic import BaseModel, Discriminator, Tag
from typing_extensions import Annotated

class TypeKey:
pass
def constructor(loader, node):
data = loader.construct_mapping(node)
data[TypeKey] = node.tag[1:]
return data


def make_constructor_enum(cls):
if isinstance(cls, type(IntEnum)):
def constructor_enum(loader, node):
data_str = loader.construct_scalar(node)
for item in cls:


/r/Python
https://redd.it/1f0oud5
Track migration files in git : What are the good practices ?

The title is quite explanatory, I am still unsure of what is the best way to go about it. What do you guys do ?

/r/django
https://redd.it/1f0s0gc
I switched from full stack to streamlit/python and it reduced my development time to 2 weeks !

Just 2 months ago, I was always building full stack apps that took me ages to build and rarely found any traction.

I am pretty good with python, so I was looking for a quick way to prototype my idea and validate it.

The hidden gem there was Streamlit, a python package that makes it possible to turn your scripts into apps and deploy them on the cloud.

You don’t have to worry about backend or even only limited on frontend. Your job is just to integrate the functionality. I am not associated to Streamlit anyhow, but I just wanted to show for anyone who did not know it before that it is a great way for prototyping. 🙏

In my case, I have connected the OpenAI API, built out a custom python script, connected a Supabase Database and integrated it into the Streamlit front end.

It is also possible to use common packages like pandas or matplotlib to visualise results pretty easily and make them interactive. 🆙

/r/Python
https://redd.it/1f07c7d
🛠️ Hands-On with llmio: Let's Build an AI Task Manager 🤩

Hey r/Python and fellow developers!

Earlier this week, I shared an introduction to [**llmio**](https://github.com/badgeir/llmio), a lightweight Python library I developed for building LLM-based agents with ease. I really appreciate the positive feedback and the support from those who checked it out!

Today, I’m following up with something every developer has probably built at least once—a todo-list app! 🤩 Yes, it’s a classic, but it’s also a perfect example to show how llmio can be used in real-world applications. Specifically, I’ve put together a [notebook](https://github.com/badgeir/llmio/blob/main/examples/notebooks/simple_task_manager.ipynb) that demonstrates how to create a simple Task Manager using `llmio`.

### 🔧 A Quick Recap of Key Features:

- **Type Annotation-Based Tooling**: Define tools effortlessly using Python’s type annotations.
- **Broad API Compatibility**: Works out of the box with OpenAI, Azure, Google Gemini, AWS, and Huggingface APIs.
- **Lightweight**: A minimalistic library that integrates seamlessly into your projects without adding unnecessary bulk.

### 💻 Demo: Building a Task Manager with `llmio`

In this [notebook](https://github.com/badgeir/llmio/blob/main/examples/notebooks/simple_task_manager.ipynb), I walk through how to build a Task Manager that can list, create, update, and delete tasks. This example showcases `llmio`'s ability to leverage LLMs for practical applications while maintaining control over task execution and context management.

### 🚀 Getting Started:

- **Install**: `pip install llmio`
- **Example**:
```python


/r/Python
https://redd.it/1f0upad
Any hints/ideas on how to make this?

/r/django
https://redd.it/1f0vhdx
Let's write FizzBuzz in a functional style for no good reason

# What My Project Does

Here is something that started out as a simple joke, but has evolved into an exercise in functional programming and property testing in Python:

https://hiphish.github.io/blog/2024/08/25/lets-write-fizzbuzz-in-functional-style/

I have wanted to try out property testing with Hypothesis for quite a while, and this seemed a good opportunity. I hope you enjoy the read.

Link to the final source code:

- https://gitlab.com/HiPhish/functional-fizzbuzz
- https://github.com/HiPhish/functional-fizzbuzz

# Target Audience

This is a toy project

# Comparison

Not sure what to compare this to

/r/Python
https://redd.it/1f0ywkp
Services and Utilities: Best practice?

Hello all,

Been learning Django for a year or so and working on two production apps. What's your best practice with the location of service or utility functions? I'm looking at two options;

1. Utils folder at the same level as my apps -> utils/services.py
2. App level service layer -> my_app/services.py

Thanks all!



/r/django
https://redd.it/1f1002k
Google News Scraping

Hello, I'm conducting research that involves collecting data from Google News. My goal is to determine how many times a country is mentioned in the titles of specific news websites. The query might look like this: 'intitle:[Country name\] site:[Website.com\]'. After running the query, I need to count the number of results. Doing this manually would take a long time, so I'm looking for an automated solution.

/r/Python
https://redd.it/1f0mvhl
Monday Daily Thread: Project ideas!

# Weekly Thread: Project Ideas 💡

Welcome to our weekly Project Ideas thread! Whether you're a newbie looking for a first project or an expert seeking a new challenge, this is the place for you.

## How it Works:

1. **Suggest a Project**: Comment your project idea—be it beginner-friendly or advanced.
2. **Build & Share**: If you complete a project, reply to the original comment, share your experience, and attach your source code.
3. **Explore**: Looking for ideas? Check out Al Sweigart's ["The Big Book of Small Python Projects"](https://www.amazon.com/Big-Book-Small-Python-Programming/dp/1718501242) for inspiration.

## Guidelines:

* Clearly state the difficulty level.
* Provide a brief description and, if possible, outline the tech stack.
* Feel free to link to tutorials or resources that might help.

# Example Submissions:

## Project Idea: Chatbot

**Difficulty**: Intermediate

**Tech Stack**: Python, NLP, Flask/FastAPI/Litestar

**Description**: Create a chatbot that can answer FAQs for a website.

**Resources**: [Building a Chatbot with Python](https://www.youtube.com/watch?v=a37BL0stIuM)

# Project Idea: Weather Dashboard

**Difficulty**: Beginner

**Tech Stack**: HTML, CSS, JavaScript, API

**Description**: Build a dashboard that displays real-time weather information using a weather API.

**Resources**: [Weather API Tutorial](https://www.youtube.com/watch?v=9P5MY_2i7K8)

## Project Idea: File Organizer

**Difficulty**: Beginner

**Tech Stack**: Python, File I/O

**Description**: Create a script that organizes files in a directory into sub-folders based on file type.

**Resources**: [Automate the Boring Stuff: Organizing Files](https://automatetheboringstuff.com/2e/chapter9/)

Let's help each other grow. Happy

/r/Python
https://redd.it/1f1anh6
In flask I have a function that updates different columns in flask sqlalchemy but the columns won't update. Put simply the update doesn't have any effect on the code. What am I doing wrong?

        return redirect(url_for('auth.login'))
        return redirect(url_for('auth.login'))

# now is added because of pytest + now represents the current time
def reset_attempts_token_tried_to_0(user_db, now):
'''
if the max attempts of the token tried is exceeded + the
token is expired reset the attempts_token_tried to 0.
'''

# why doesn't work
time_token_expired_db = user_db.time_token_expired
# executes at 9:00 <= 9:30pm
current_time = now

#delete
flash(f'user_db.attempts_token_tried {user_db.attempts_token_tried}')
flash(f'current_time {current_time}')
flash(f'time_token_expired_db {time_token_expired_db}')



/r/flask
https://redd.it/1f14zga
Giving OTP sms

I wanted to implement OTP service on my django project so is there any free service for this to implement it

/r/django
https://redd.it/1f1csmd
Hiring Full Stack Developer

Hi developers, we have added a new job listing on our platform. If you are interested in this job please check the job link below.

Role - Full Stack Developer (Remote, Full Time)

Job Link - devloprr.com/jobs#288

/r/flask
https://redd.it/1f1fp81
I am getting the following error. "AttributeError: 'NoneType' object has no attribute 'save'.

error:
Traceback (most recent call last):
File "C:\\Users\\mmhta\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\flask\\app.py", line 1498, in __call__
return self.wsgi_app(environ, start_response)
\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^
File "C:\\Users\\mmhta\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\flask\\app.py", line 1476, in wsgi_app
response = self.handle_exception(e)
\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^
File "C:\\Users\\mmhta\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\flask\\app.py", line 1473, in wsgi_app
response = self.full_dispatch_request()
\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^
File "C:\\Users\\mmhta\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\flask\\app.py", line 882, in full_dispatch_request
rv = self.handle_user_exception(e)
\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^
File "C:\\Users\\mmhta\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\flask\\app.py", line 880, in full_dispatch_request
rv = self.dispatch_request()
\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^
File "C:\\Users\\mmhta\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\flask\\app.py", line 865, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint\])(**view_args) # type: ignore[no-any-return\]
\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^
File "C:\\Users\\mmhta\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\flask_login\\utils.py", line 290, in decorated_view
return current_app.ensure_sync(func)(*args, **kwargs)
\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^
File "e:\\newsPortal\\website\\views.py", line 23, in create_post
image.save('images/' + img + '.jpg')
AttributeError: 'NoneType' object has no attribute 'save'

python:

@views.route("/createpost", methods=['GET', 'POST'])
@loginrequired
def createpost():
    if request.method == "POST":
        text = request.form.get('text')
        img = str(uuid.uuid4())
        image = request.files.get('image')
        image
filename

/r/flask
https://redd.it/1f1hhdt