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
A handy cheatsheet for Python
http://pysnippets.com

/r/Python
https://redd.it/8e1mzq
User Session and Session Data

Is there any way to store session data based on a User's session?

i.e. `request.user['foo'] = 'bar'`

I know the above code doesn't work, so I was wondering if there is something built in where you could individually store data in sessions with each user? Or is there another to do something like this, because I need to use data across different views and I need to keep it separate from each User.

/r/djangolearning
https://redd.it/8e1v8q
Impressed!

Fastest web development framework I have encountered till now.
Made a website in 24hours, which would have otherwise taken at least a week.
Thanks Flask!

/r/flask
https://redd.it/8e2o6e
What are the chances of a django site being hacked?

If you were to create a cms in Django what are the chances of it being hacked compared to using wordpress?

Would it be near impossible to get hacked via a vulnerability in your cms if nobody else has access other than you to your django source code?

What if you are lazy/don't know how to update django and python so you end up never updating django versions?

You like a look of a few apps on djangos site so add a few.. would this increase your chances of getting hacked? Does the django repository have a bad reputation of vulnerability plugins like the wordpress one?

*I ask these questions as someone with no knowledge of django but wanting to learn so I can create my own cms and move from wordpress to django.

Thanks in advance :)


/r/django
https://redd.it/8e29do
[P] Simple Tensorflow implementation of Multimodal Unsupervised Image-to-Image Translation (MUNIT)

/r/MachineLearning
https://redd.it/8e4765
Struggling with dynamic forms

I need a form that can dynamically create more fields. I have a select, and I need a number of additional parameters depending on the value of the select.

For example, imagine a select "numberOfParameters" and if the user selects 4, I want 4 new fields. This is made even worse by the fact that these are dependent selects: the options on the second select which generates more fields depends on what has been selected on the first one.

This is proving to be pretty challenging in django, is it safe to do this without forms.py in AJAX/JQuery (which is relatively easy)? Or is there a way to do it normally? (or should I just drop the idea altogether if it isn't safe).

Example of what I mean:

An application for selecting a way to travel to school.

* Users can select a school they go to.
* Depending on which school they choose there are different options for the travel, some school have busses, some only have cars, some even have boats.
* Depending on which way they want to travel, there are more options: trains have option for 1st or second class, cars have options for brand, but also for itinerary, type of fuel, type of music you want to listen to, and boats don't have any options at all.

Thanks for reading.

/r/django
https://redd.it/8e376d
How can I convert my Jupyter notebooks to organizable and searchable documentation such as devdocs.io?

Hello guys.I have thousands of code snippets and jupyter notebooks.I want to create easily, organizable, searchable documentation(such as devdocs.io) for this Jupyter notebooks.
Are there tools for doing this hard work for me?

/r/IPython
https://redd.it/8e6w43
flask whoosh alchemy: when or where do analyzers/tokenizers run?

Are texts tokenized > indexed > searched? OR
are full texts indexed > read/loaded > tokenized > searched?
Im trying to index my existing db, still trying to get it to work. But not quite sure how to go about it.


/r/flask
https://redd.it/8e7yph
This media is not supported in your browser
VIEW IN TELEGRAM
Prototype for a garage door monitor/controller using MicroPython and an ESP8266

/r/Python
https://redd.it/8e3fix
Why when SageMath was before Jupyter, only Jupyter was "accepted" in the community? What are the differences between them? I'm NOT talking about CoCalc but SageMath the software



/r/IPython
https://redd.it/8e5una
Cron script to re-save all of a model's instances

I have a pre-save receiver that updates a model with some supplemental information. I'll need to run it every day or so.

While messing around in the shell, I noticed that I have to exit out and restart the shell if I make any changes to my receiver (which I anticipate having to do).

Some googling suggested I should use importlib to reload a package, in this case profiles.models. But it's not working as I expected. Here's my script:

import importlib
import profiles.models

importlib.reload(profiles.models)

for i in profiles.models.Score.objects.all():
i.save()

I get the error:

django.core.exceptions.AppRegistryNotReady:
Apps aren't loaded yet.

Does that mean I can't run this outside of an active and running Django server? What's the right way to do this?

---
Bonus question: It seems computationally expensive to do this for every Score instance every time. If I want to select a random sample of 100 of them, would the right way to do so be this?

Score.objects.all().order_by('?')[:100]

/r/djangolearning
https://redd.it/8e5w3r
How to structure a custom built admin?

Hey guys, my application is getting much more complex and the inbuilt django admin isn't cutting it anymore.

So I've decided to build a custom admin for our most used flows.

How do I go about structuring this custom admin? Do I make a new app called `custom_admin` and house all the functionality in there, or do I just add a new `custom_admin.py` file to all my existing apps? (since I already have a lot of stuff in `admin.py`), or simply write the views in `views.py`?

One example I found is that `saleor` (a django project) have their custom admin dashboard as a separate app https://github.com/mirumee/saleor/tree/master/saleor/dashboard

How do you guys build a custom admin?



/r/django
https://redd.it/8e9bvd
Submitting multiple forms at once?

New to flask, hello :)

I have a page with two forms that are passed in as parameters.

return render_template(
'survey.html',
clientDetailsForm=ClientDetailsForm(),
houseDetailsForm=HouseDetailsForm())

I like having them as seperate forms because they represent seperate concepts.

On my survey.html I have a save button which I would like to save the values of both forms.

Additionally I have a "Send Report" button which ideally would first call the save view, then the sendReport view.

How can this be achieved?

Thanks!

/r/flask
https://redd.it/8e9fj1
Android development using Python?

Does anybody know the best way to develop for Android in Python? I've heard about a lot of packages /etc but no clear answer to "what is the best / standard / working".

/r/Python
https://redd.it/8e9wae
Are there any good continuous testing tools ?

Hello !

The C# team at my company is using a proprietary tool called [NCrunch](https://www.ncrunch.net/) which amongst other things allow us to have tests continiously running the appropriate unit tests when a part of the codebase is modified.

After working some weeks on the C# codebase, I found myself missing this feature when coding in Python.

Do you know a good tool for continuous testing for a Python codebase ?

Thanks in advance for your feedbacks :)

[EDIT 1]: We already have set up continuous integration on our [Jenkins](https://jenkins.io/) server.

[EDIT 2]: I do not try to find a replacement for NCrunch, but instead I am looking for its equivalent for Python codebases :)

[EDIT 3]: Teamates told me about [Wallaby.js](https://wallabyjs.com/) which is an continuous testing tool for JavaScript. If this kind of stuff exists for JS, I am confident that it can be done for Python too !

/r/Python
https://redd.it/8ea9lx
sqlalchemy queries

I am learning about flask and sqlalchemy and I have a question about the ways to make queries. I have seen three types of querys: cls.query, db.session.query and model.query. I want to know what are, if there are, the differences between these three methods? Or do the do the exact same thing?

/r/flask
https://redd.it/8eb8go