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
how do i import javascript files?

hi guys,

i am making a website that will run in a close network, as a part of that i had to download all the bootstrap files into a local folder so it wont access the net.

for some reason, i can import my css files as i do :

<link rel="stylesheet" href="{url\_for ('static',filename='bootstrap.css')}" >


but doing the same for javascript wont work:

<script type="text/javascript" src="{url\_for ('static',filename='bootstrap.js')} "></script>


&#x200B;

thank you!

/r/flask
https://redd.it/b7rhl7
How to set up conditional Admin Inlines in Django 2.2

I have a model with three different related fields. There are also three inlines, one for each relation. I want to be able to display only ONE inline based on another property (`type`). So, if `type == 0`, show Inline #1 etc.

Here is the code that I am using (based on Django Docs: https://docs.djangoproject.com/en/2.2/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get_inline_instances):

class Event(admin.ModelAdmin):
inlines = [ResultTrialsInline]

def get_inline_instances(self, request, obj=None):
if obj.type == 1:
return [ResultTrialsInline(self.model, self.admin_site)]

return []

However, I keep getting the following error when changing the type on an existing model:

['ManagementForm data is missing or has been tampered with']

Is there a wat to solve this?



/r/djangolearning
https://redd.it/b7m6mj
I wrote a script to convert an RGB image to an excel spreadsheet.

Github repo with explanation: [https://github.com/takacs/pixel\_spreadsheet](https://github.com/takacs/pixel_spreadsheet)

/r/Python
https://redd.it/b7t6jq
When coding with python makes a turn for the worst...

/r/Python
https://redd.it/b7xdhe
Simulating traffic for a django site?

I have a site that is struggling to handle its peak traffic, which peaks on specific days due to the event-based nature of the site. As I work on scaling it, I'd like to be able to simulate the traffic to make sure things don't break down before the next event, which is a really important one.

How can I do this? Write a web scraping script and launch 5000 instances against my site? I'm not sure what the best/common practices here are, so any advice or suggestions are appreciated!



/r/django
https://redd.it/b7r7ud
End-to-end python script to generate mosaic posters made from scenes extracted from movies. https://github.com/SouravSharan/photomosaic

/r/Python
https://redd.it/b7ye9z
Time outs on the large files download.

Hello! I have flask + gunicorn + nginx. I wrote a simple app to fetch log files from a remote sever and zip and download. It works fine for files under 1gb. Some files are over 1gb or sometime 3-4gb, how can I send these files with out timing out. I have used gevent worker but it still does timeout. Please advise. Thanks.

/r/flask
https://redd.it/b7wts4
[P] PyTorch implementation of "Incremental Network Quantization: Towards Lossless CNNs with Low-Precision Weights"

I found Incremental Network Quantization an interesting way to perform quantization aware training. However the original code is a modified version of the caffe source code and not that user friendly. I reimplemented it into a pytorch library that is easy to use.

Code: [https://github.com/Mxbonn/INQ-pytorch](https://github.com/Mxbonn/INQ-pytorch)

Original paper: [https://arxiv.org/abs/1702.03044](https://arxiv.org/abs/1702.03044)

/r/MachineLearning
https://redd.it/b817fz
Convert argparse to class syntax for Jupyter notebook execution

Hi, this script converts argparse to class syntax.

As Jupyter is not compatible with argparse. I hope it would be helpful for your testing.

web convert: [http://35.192.144.192:8000/arg2cls.html](http://35.192.144.192:8000/arg2cls.html)

/r/IPython
https://redd.it/b8c3gk
I made this figure in python as a masters student and it's still my favorite

/r/Python
https://redd.it/b8buj2
Huey task queue 2.0

Hello r/python. I've released a new version of [Huey](https://huey.readthedocs.io), a lightweight task queue. Huey is an alternative to celery, rq, etc, and offers a ton of functionality in a small package. Features:

* Easy to use: `@huey.task()`
* Redis or sqlite support built-in
* multi-process, multi-thread or greenlet task workers
* schedule tasks to run at a future time, or after a given delay
* schedule recurring tasks, like a crontab
* automatically retry tasks that fail
* task prioritization (new)
* result storage
* task locking
* task pipelines and chains
* optional django integration

I started this project about 7 or so years ago and am quite happy with how it's developed. The codebase is very small and self-contained, so it's hopefully very easy to use and understand. If you have any questions, feel free to ask and I'll do my best to answer.

[Changes in 2.0](https://huey.readthedocs.io/en/latest/changes.html), not to mention I rewrote most of the documentation for this release.

[Code](https://github.com/coleifer/huey)

/r/Python
https://redd.it/b8bkk2
Save Image in MongoDB with MongoEngine

Currently I am learning the mongoengine and just made the video for saving image files directly in MongoDB , wish you like it.

[https://youtu.be/PO-z4nwdMUs](https://youtu.be/PO-z4nwdMUs)

MongoEngine works very well with flask and mongodb! If you have any suggestion and questions, please leave the comment. I am very happy to know all of you. :)

/r/flask
https://redd.it/b88o0u
How can I pass data between SelectMultipleFields?

**[UPDATE]**

After banging my head against this all weekend, I finally found the answer. The problem is that the default validators in `SelectMultipleField` don't actually work. If I replace `validate_on_submit` with `is_submitted`, the code runs. This version does what I want it to:
```
@streams_blueprint.route('/select', methods=['GET','POST'])
def select():
# Grab a selectable list of studies from database.
form = SelForm()
db_objects = [(stream.id, stream.name) for stream in Stream.objects()]
form.selections.choices = db_objects
if form.is_submitted():
form2 = SelForm()
selections = form.selections.data
new_objects = [(stream.id, stream.name) for stream in Stream.objects(id__in=selections)]
form2.selections.choices = new_objects
else:
form2 = SelForm()
return render_template('select_streams.html', form=form, form2=form2)
```
If I need validators, I will have to write custom ones for this field type.

**[ORIGINAL]**

I'm new to Flask and WTForms, and have been really struggling with this simple task. I want to display a list of options. The user can select multiple options, and then these choices generate a new

/r/flask
https://redd.it/b7gnhg
RPI 3 B+ Virtual ENV

I know what a VENV is and how it works but i dont get how i link my python script to the Env. Anybody who can explain?

/r/Python
https://redd.it/b8gwk3
Dynamic Dashboard stats with Flask, Redis and Postgres

I have an admin application that has a dashboard page with various statistics for our company. Basically our data is stored in Redis, and right now still thinking of a way to combine Postgres and Redis to work together as both our data store.

&#x200B;

Any idea how I can update the dashboard dynamically? Say like every 5 minutes or depending on what we set, it doesn't have to be real time.


My thinking is that, I will run a background job that will pre aggregate data on redis and store that on Postgres for record, then when a user refreshes the dashboard or visits the dashboard, it will fetch the latest aggregated data from Postgres. Maybe use AJAX to update the dashboard periodically.

/r/Python
https://redd.it/b8hg7k