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
Flask changing src and PATHS

I've used Flask(__name__, template_folder="mijn_project/templates") for some reason all my PATHS don't work. app.py is stored in / and my project is stored in /mijn_project/. none of my templates can find the images location or bootstrap, css, js etc. but when I run my HTML template it show the CSS, images, lib without errors. what's going wrong? PS. the structure is not my idea, my teacher demands this. and I tried every PATH ../static, /static/, ../../static but nothing works. and its a local test

/r/flask
https://redd.it/12n3w4m
How do I get current values from the database in a dropdown form

Hi,

TL:DR: I want to pass the values of a database model into the options in a dropdown menu.

I am building a application with different card types. Each card type has a different color. To keep track of the users preferences I created a database model where for each user I keep track of their color (and also Icon and label).

Basically the user can say:- legend_1 is yellow, I call it "ambition" and I want a thumb up icon.- Legend_2 is blue etc etc

here is the model:

models.py

# Create your models here.
class CardPreferences(models.Model):
<!--Some other stuff not related to question -->
legendlabel1 = models.CharField(blank=False, maxlength=40, default='legend1')
legendhexcolor1 = models.CharField(blank=False, maxlength=6, default='78E7BF')
legendicon1 = models.CharField(blank=False, maxlength=40, default='thumbs-up-solid.svg')
legend
label2 = models.CharField(blank=False, maxlength=40, default='legend2')
legend
hexcolor2 = models.CharField(blank=False, maxlength=6, default='51c1ff')
legend
icon2 = models.CharField(blank=False, maxlength=40, default='thumbs-up-solid.svg')


/r/djangolearning
https://redd.it/12o8jow
Database on Local Machine - Still Pulling Heroku Postgres Database

Recently my main computer rig died and I moved onto a new computer.

I am trying to get my local development mode back up and running but am running into trouble, amateur programmer at best, doing this as a fun hobby.

Anyways, in the process of trying to get the website back up and running, I forgot to set my local environment variable of "DEVELOPMENT_MODE" to "True" and ran "python manage.py collectstatic" and "python manage.py runserver" and my local machine points to the postgres database that I have on with Heroku.

I thought this should be a pretty easy fix and change "DEVELOPMENT_MODE" to "True", but the local database is still referencing the postgres database. Any ideas on how to get django to point the the local sqlite3 database?

Code in reference, settings.py:

if DEVELOPMENTMODE is True:
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": os.path.join(BASE
DIR, "db.sqlite3"),


/r/djangolearning
https://redd.it/12kb0gg
Flask Sessions not working with blueprints

I am using flask sessions, i recently changed my code structure to be blueprint based, it has broken sessions. Whevenver i try to access sessions inside a blueprint, it is giving me
RuntimeError: The session is unavailable because no secret key was set.  Set the secret_key on the application to something unique and secret.


This is the code from the main application:
app = Flask(__name__)
app.register_blueprint(authModule, url_prefix='/auth', cookie_path='/')
app.secret_key = environ.get('secret_key')
app.config['SESSION_COOKIE_PATH'] = '/'


Can anybody tell me what is causing this?

/r/flask
https://redd.it/12oexr1
I want to display a stock market ticker on a HTML page.

Here's the Github link to my code : https://github.com/SachinPrab/microinvestment/blob/81d2e32fcd48d58704ad2668d05164d2f2ad33c0/app.py

I want to display the output of the above code in this HTML page (Github link) : https://github.com/SachinPrab/microinvestment/blob/81d2e32fcd48d58704ad2668d05164d2f2ad33c0/ticker.html

The above page should be opened when the user clicks on the button at the bottom of this page: https://github.com/SachinPrab/microinvestment/blob/81d2e32fcd48d58704ad2668d05164d2f2ad33c0/stocks.html

Can someone please point out the error in the Flask application that I have created? I am able to view only the heading which reads "Stock Market Ticker" upon running the code in PyCharm editor but I'm not able to view the ticker. Thanks in advance.

/r/flask
https://redd.it/12kqncf
Announcing Polyfactory - a powerful mock data generator for dataclasses, Pydantic and more

Hello r/Python!

Today I'd like to formally announce the first stable release of Polyfactory \- a powerful mock data generator built around type hints and support for some of the most popular data modelling solutions such as Pydantic models, dataclasses, typed-dicts and more!

## Once upon a time there was pydantic-factories

Some of you may already know this project as "pydantic-factories"; A name under which it garnered a decent amount of popularity since it's inception. Pydantic-factories and Polyfactory have a lot in common. In fact, Polyfactory is pydantic-factories 2.0. That's why we also decided to continue the version number and release the first version of Polyfactory as 2.0.0.

But why the name change?

A main motivator for the 2.0 release was that we wanted to support more than just Pydantic models, something which also required a change to the pydantic-fatories' core architecture. As this library would no longer be directly tied to Pydantic, polyfactory was chosen as a new name to reflect its capabilities; It can generate mock data for dataclasses, typed-dicts, Pydantic, odmantic, and beanie ODM models out of the box.

Polyfactory is all that pydantic-factories was and more!

## So what can it do?

Let's look at a very basic example using dataclasses:



/r/Python
https://redd.it/12o69ld
Fluke v0.3.0 has been released!

Fluke is a Python package that can be used to easily read files that do not reside within the local file system, e.g. on a remote server or on the cloud, as well as transfer them between said locations.

Most changes introduced in version 0.3.0 are focused on reading files, adding functionality regarding reading large files in chunks, partially reading files, and more.

Github: https://github.com/manoss96/fluke

Docs: https://fluke.rtfd.io/

Any feedback is welcome!

/r/Python
https://redd.it/12oef63
Trying to implement symmetric encryption in a secure way

Hi friends. Need some guidance here.

I'm creating a Django app which encrypts some fields before storing in Db (using custom fields). I want the server to have little to no knowledge of the contents (not able to get to zero knowledge yet).

So here's what I'm trying to do:

When the user signs in, use the password to generate a key using PBKDF2
Put it in session storage
Use this key to encrypt/decrypt (using AES) any sensitive data they enter
Once they logout, session gets cleared, key gets destroyed, server has no way to decrypt the data

# Q1

Is this a good approach? Or are their better alternatives or packages which already implement this sort of thing?

# Q2

I'm currently using PyCryptodome to generate PBKDF2 key, but it returns byte object which is not JSON serializable, and hence not able to store it as session variable. How do I go about doing that?

/r/django
https://redd.it/12ohklt
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/12ou5no
Using first name and last name as username

Building a Django site for my work. I want to make it simple and automatically assign a username based on the users first letter of their first name and then their whole last name.

I’m using Django Forms and following along with a tutorial to set forms up.

Can this still be achieved and how would it be achieved?

/r/djangolearning
https://redd.it/12onqoy
How to implement Push notification in django.

Hello guys I build a django and react native mobile app. Now I want to send push notification from django to my React native app. How should I do that and packages to used for sending push notification. There are very less resources for django push notification. If you guys implemented than let me know the process. Any kind of help would be appreciated. 🙏

/r/django
https://redd.it/12o9lm3
ConnectionAbortedError when the page's loading is canceled by the user (Python3 Quart)

The error ConnectionAbortedError is thrown if the page's loading is canceled when using a Python3 Quart webserver. Using @app.errorhandler(ConnectionAbortedError) with an appropriate function is completely ignored. How do I handle this error?

/r/flask
https://redd.it/12oyomm
Is Flask an appropriate choice for building a collaborative document website?

I was afraid this might be beyond Flask's ken. Should I consider using more involved frameworks like Django?

/r/flask
https://redd.it/12ov0lc
[R] Timeline of recent Large Language Models / Transformer Models

/r/MachineLearning
https://redd.it/12omnxo
total beginner got a python project and want to convert in to flask to use in flutter as an API

I got a Python project which works perfectly fine in the console but I want to use it in my Flutter app. I can't directly use I have to deploy this project on a web server for that I need to convert this into a Flask app but i am a total beginner in Flask and python so someone please help to do this. I am giving you a brief of what this Python project does so it is a chatbot it asks questions as per the intent file and gives the answer which is data from the SQL server. I want to create a Flask app for this project which also does the same as this project I am providing the whole codebase of this project =>

import json
import os
import numpy as np
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Embedding, GlobalAveragePooling1D
from tensorflow.keras.preprocessing.text import Tokenizer
from tensorflow.keras.preprocessing.sequence import pad_sequences
from sklearn.preprocessing import LabelEncoder
import json
import pyodbc
import numpy as np
from tensorflow import keras
from sklearn.preprocessing import LabelEncoder
import pyodbc

/r/flask
https://redd.it/12p9c49
pytheus: a modern python library for collecting prometheus metrics built with multiprocessing in mind

hello, I wanted to share a library I've been working on for quite some time now.

It's a new python library for collecting metrics with prometheus with a focus on flexibility & multiprocessing. The last one is one of the main reasons for this to be born as I found it difficult to have multiprocessing work correctly with the existing ecosystem.

Going from single process to multi process is a matter of a "function call" and everything should work as expected without differences in features between the two.
The library also supports default labels and partial labels (incrementally build your child instance), and offers ways to easily plug in your own version of something if you so require via protocols. (For example a custom Registry or even a custom Backend for multiprocessing using something else, by default it uses redis).

A lot of focus was also given to the documentation to make it clear.
I hope that if you struggled in the past this might make the experience better! :)


repo: **https://github.com/Llandy3d/pytheus**

docs: **https://pythe.us/**

/r/Python
https://redd.it/12pcvg0