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
Using SQLAlchemy JSON object type vs creating an extra relation for storing a list of URLs?

I am considering which option would be better, I basically want to store a list of URLs, which I can modify at will and delete if I need to.

Store a regular list in the table as a db.JSON? or create a separate table and relate it back to the original table (it'll only have one parameter, the URL)

/r/flask
https://redd.it/c9tsu4
Django Beginner

Hi everyone! I am sort of new to Django, I have sucessfully used it a couple times for large/small projects. Right now I just want to get my project started and I am having a ton of trouble. I start off by creating a python environment. I then activate the environment. After that I use pip to install Django to the environment. After that I try to create my project with [django-admin.py](https://django-admin.py) startproject mysite. When I type this command, it always says "bad interpreter no such file or directory". However, it does start a new project if I do django-admin (without .py). But it seems to create a project using amn older version of Django. I just want to get past this barrier so I can start my project.

/r/django
https://redd.it/ca1h8o
Trouble with SQLite

Hey all,

This is my first web app project and I am having issues using SQLite for my database. I’m having trouble finding tutorials or documentation that describes how to implement this into my flask project easily for a complete beginner. I’ve gone through a few and was wondering if anyone had a good recommendation. The database I need is very simple and only has one table for right now.

Thanks!

/r/flask
https://redd.it/c9srir
What is the best way to refresh a token using the old token?

I'm using Djoser and it provides several endpoints, but I do not know how to update an X token in X minutes. There seems to be no endpoint for this.

​

Basically, I want to refresh the access token every 5 minutes by making api calls on my front end. But as for the back, I do not know what to do about it.

/r/djangolearning
https://redd.it/c9zm30
How much should a django freelance developer charge hourly

I am confused about how much amount I should charge. Also wanted to know whether doing django freelancing is worth it or not.

/r/django
https://redd.it/ca576e
Flask vs NodeJS for API that delegates calls to Python scripts: What are benefits/downsides for either case?

I'm about to build a Flask API that runs python scripts on requests.
Using Flask seems more logical and beautiful since then all code in my web-app will be in Python.
On the other hand, the front-end is Javascript/React, so for convenience-sake maybe it doesn't matter that much? Also, I've read that NodeJS can be faster. The biggest concern is that it needs to be scalable and fast.

What's your opinion on this?
Thanks!

/r/flask
https://redd.it/ca6m45
Limiting the amount (not size) of files a user may upload (based on groups)

So I’m a Django newb and really a python newb too but I’m making my first web app.

I want to allow my users to upload certain amounts of files based on membership level.

10 mp3 files at free tier, or unlimited at the paid tier. There will also be wav files in the same amount but irrelevant really I think, because it will be the wav version of the mp3.


So I haven’t created the groups yet, and I haven’t figured out how to make a user pay to become a member of the group, but I think there is a lot of info out there on that.


Currently the users upload files and I use a list view to populate an html5 based audio player with the songs filtered by the logged in user. So each user only sees their own songs in the player.

My question is, can I do something like have a validators.py file that says if a user is in group free group and the amount of files uploaded by user id >= 10, throw an error stating that they need to upgrade membership?


I know it will be more complicated than this, but am I thinking

/r/django
https://redd.it/ca9qne
[P] A little gadget that plays rock-paper-scissors slightly better than random using a small quantized RNN running on an 8-bit microcontroller

[Project video here](https://www.youtube.com/watch?v=iuTKBHW0OaU)

[Code and PCB/CAD design files here](https://github.com/PaulKlinger/rps-rnn)

I was looking for some kind of project that let me combine my love for building [small electronics/3d-printing projects](https://paulklinger.com/projects/) and machine learning, and this is what I came up with.

The machine learning side of this isn't too interesting, just [a small 3 layer vanilla RNN](https://raw.githubusercontent.com/PaulKlinger/rps-rnn/master/diagrams/rnn_architecture.png) (all layers with 10-d state, trained in tensorflow/keras) that takes as input the moves of the two players and outputs a prediction for the opponents next move. The data comes from human games played on [roshambo.me](https://roshambo.me) via this [blog article](https://justincollier.com/life-hacks/how-to-win-rock-paper-scissors/). I added some simulated data of periodic sequences, because that seems like the sort of thing people might try out when playing against an "AI".

Without the simulated data (which is easy to predict) the model gets something like 38% accuracy on the test set (compared to 33% playing randomly). One nice thing about rock-paper-scissors is that you can't do much better than random, so there isn't much pressure ;)

I had some problems getting training with larger batches to work (either with just padding or padding and masking the gradients) so I just trained it with batch_size=1, which wasn't too bad for such a small network.

The probably more interesting

/r/MachineLearning
https://redd.it/ca88r4
This media is not supported in your browser
VIEW IN TELEGRAM
I made a tool to download and set wallpapers from Reddit.

/r/Python
https://redd.it/caac6i
How fast can Django generate model instances?

Hey all. I've got what I think is a simple question about Django: How fast can it generate model instances?

I've got a CSV file with about 2.5 million rows and I want to generate a model instance for each row. They will all be the same model, basically with the headers of the CSV as fields and the rows as records.

It's easy to just read the CSV line by line and for each line, create the model w/ the given fields, but is this a terrible idea? How fast can Django create instances like that, and is this a common operation or should I reconsider my database design? Also, would it be accurate if I were to load all this data into sqlite and search/filter/write my code around that locally, if I plan to eventually push it into a Postgres database in production?

For what it's worth, my intention is to make this data searchable, where almost every query will be a `Thing.objects.filter(some_column__lte=value, some_other_column__gte=other_value)` and so on w/ the ability to filter on as many of the CSV headers as possible.

Any thoughts? Open to other questions/ideas that can help me solidify my plans here :)

Thanks!

/r/djangolearning
https://redd.it/cafgfs
[AF] [CRITICAL] WORKER TIMEOUT (pid:7) Can I extend the timeout to more than 10 minutes?

Hi all,

I'm running gunicorn / flask in a docker-compose setup and I'm processing a large set of CSV files in the background.

It's always worked fine but I have a particularly large set I'm working through and after about 10 minutes I get this error and the conversion of the CSV starts again from scratch.

website_1 | [2019-07-08 05:41:02 +0000] [1] [CRITICAL] WORKER TIMEOUT (pid:7)
website_1 | [2019-07-08 05:41:02 +0000] [7] [INFO] Worker exiting (pid: 7)
website_1 | [2019-07-08 05:41:02 +0000] [9] [INFO] Booting worker with pid: 9

This is obviously annoying as the file never finalises processing.

Is there a way to extend the timeout? Any guidance much appreciated.

/r/flask
https://redd.it/cah4hk
How To Intercept Email In Flask?

I would like to intercept the email before sending to client like ROR [https://guides.rubyonrails.org/action\_mailer\_basics.html#intercepting-emails](https://guides.rubyonrails.org/action_mailer_basics.html#intercepting-emails) , But is there anyway that we can do it in flask?

​

Thank you for helping me.

/r/flask
https://redd.it/cahqmd
I wanted to know how bad was the heat wave in my bedroom, so I use a cheap sensor and a raspberry and built an acquisition station !

Hello guys ! With the rising temperature, I wanted to observe the temperature variation in my bedroom (under the roof, hell on earth). So I scraped the sensor I bought some time ago, and connect a DHT sensor (humidity and temperature) in the Raspberry GPIO.

​

I wrote a small application in python with

​

\- data acquisition thanks to AdafruitDHT lib

\- data storage in a mongodb

\- web API with bottle

​

I put it into a repository if anyone interested to do the same at home !

​

[https://gitlab.com/celliern/sensor](https://gitlab.com/celliern/sensor)

​

Cheers

/r/Python
https://redd.it/caig3g
Django Oscar vs Saleor for Digital Products store?

We run [https://videoplasty.com/](https://videoplasty.com/) \- a pretty standard stock video marketplace (video animation, gif animation, vectors)

​

We want to start building a new custom Django platform using one of those two. Down the road, we'd like to add multivendor functionality (none of them have this at the moment)

​

Anyone have any experience with the two for digital products or knows the pros/cons of each? It's hard to find a comparison or pick one.

​

We're inclined to go with Saleor cause it looks and feels nicer (we're not developers), but some developer suggested Oscar might be better for us, so we're confused right now.

​

Would appreciate your thoughts :)

/r/django
https://redd.it/cajmmb
How to display date time like day/month/year 15:30 (24 hour time)

# Answered: { value|date:"d/m/Y G:i" }

​

Hi want it so my it show up like this: day/month/year 15:30 - with the time being 24 hour time (military time)?

I have tried this in my templates file

# dashboard.html
{ value|datetime:"SHORT_DATE_FORMAT"|time:"H:i" }

Now the date will display fine when I don't have the |time how do I add the time?

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