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
Sunday Daily Thread: What's everyone working on this week?

Tell /r/python what you're working on this week! You can be bragging, grousing, sharing your passion, or explaining your pain. Talk about your current project or your pet project; whatever you want to share.

/r/Python
https://redd.it/uptmup
How do you name the project directory?

It is about convention so I can do whatever I want at the end of the day. But let me ask this question.

By "project directory" I mean the inner mysite/ directory in the official Django tutorial.

In the official tutorial, the outer directory and the inner directory have the same name and I find it kind of confusing.

So I named it "config". But something doesn't feel right.

And I still find it confusing because you can have other config files or directories when developing with Django such as setup.cfg and pre-commit-config.yaml etc...

I prefer "project_config". But the name's kinda long and as far as I know, nobody uses it.

Some people apparently prefer"project".

https://forum.djangoproject.com/t/project-naming-conventions/339

What do you think about the name "project_config"? Redundant?

And how do you name the project directory?

/r/django
https://redd.it/uq06st
I made a package that prints trees to the console

​

https://preview.redd.it/ig0oabgn6lz81.jpg?width=469&format=pjpg&auto=webp&s=5d4114e527373799d18d77d193f1071f1c6c13c0

https://github.com/AharonSambol/PrettyPrintTree

I couldn't find any good way to print trees to the console... So I made one :)

It helps a ton with debugging!

/r/Python
https://redd.it/uq0bdo
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/uqixn0
Where to put things to be shared among different apps

I'm working on a personal project relating the backend for a point of sale app. I'd like to know the best approach for locating things like Models, Serializers and Views (among other things) that are not related to a specific app and are shared among all of them.

For example, my apps are:

* authentication (relating users)
* client
* quote
* sale

I added a new app called helper which for example has:

* A model module where a have a BaseModel with *created\_at* and *updated\_ad* fields from which most of my models on my apps inherit.
* A views module that has CRDViewSet and CRViewSet, which are Create Read Delete and Create Read ViewSets which inherit from GenericViewSet and the needed mixins, and are used on some views on the other apps.
* A validators module with functions that validate things like a positive value, not negative value, and acceptable future date, among other things which also are validations shared and used in different serializers on my apps.

Is it okay for this *helper* app to exist or is there a more recommended way to have these different structures which are shared among apps?

​

Edit: Thanks for all your answers, I agree that core sounds a lot better

/r/django
https://redd.it/urddpe
Trying to access an element in the dictionary but it's printing the entire dictionary

debug={
"cat":"cat-value",
"dog":"dog-value
}
When I run the following:
{% for cat, value in debug.items %}
{{ value }}
{% endfor %}

The output is "cat-value dog-value", the entire dictionary. How do I only take "cat"

/r/django
https://redd.it/urszoo
Dockerizing a Flask app : FileNotFoundError: Errno 2 No such file or directory: '/app/app.py': '/app/app.py'

Hello everyone, I hope you're doing great.

I'm desperatly trying to dockerize an opensource Flask app (open web calendar).

But I keep getting this error at the end:

FileNotFoundError: Errno 2 No such file or directory: '/app/app.py': '/app/app.py'

But the weird thing is that I get this error from running app.py which is definitely in /app.

I have pushed all the files to a GitHub repo. An other even weirder thing is that if I use git-clone \-> python app.py on my computer, the app works like a charm but if I do the exact same two commands inside a Python 3.7.9 container it crashes with this error (I was using python:3.7.9-slim-buster image)...

This is why I'm quite sure it's not an issue with my Dockerfile.

EDIT: As requested by many, here is the Dockerfile:

FROM python:3.7.9-slim-buster

WORKDIR /app

COPY requirements.txt /app
RUN pip3 install --no-cache-dir -r requirements.txt

COPY . /app

CMD "python3", "/app/app.py"

I am using Python 3.7.9 (as specified in the runtime.txt).

Here is the

/r/flask
https://redd.it/usclze
Wednesday Daily Thread: Beginner questions

New to Python and have questions? Use this thread to ask anything about Python, there are no bad questions!

This thread may be fairly low volume in replies, if you don't receive a response we recommend looking at r/LearnPython or joining the Python Discord server at https://discord.gg/python where you stand a better chance of receiving a response.

/r/Python
https://redd.it/urzy9j
Code cells not showing in HTML

After one of the recent updates I have a problem with HTML-output. The list of possible formats in the “Save as” menu has some new elements. Including “HTML without code”.
However, when I try to save a HTML-file I never get any code cells. Not when using the mentioned alternative (as expected), nor when I use the regular “Save as HTML”- option. The files are identical.


Does anyone have any idea? 💡

/r/JupyterNotebooks
https://redd.it/usemhs
How to Run Jupyter In Any Cloud With TPI Terraform Plugin

The following study shows a few distinct advantages of TPI to solve pain points related to maintaining your software and hardware stack as well as being limited by the hardware you own: [Using Jupyter/TensorBoard In Any Cloud With One Command](https://www.devforce.one/16373548/how-to-run-jupyter-in-any-cloud-with-one-command#/)

* Lower cost: use your preferred cloud provider's existing pricing, including on-demand per-second billing and bulk discounts.
* Auto-recovery: spot/preemptible instances are cheap but unreliable. TPI reliably and automatically respawns such interrupted instances, caching & restoring the working directory in the cloud even when you are offline.
* Custom spec: full control over hardware & software requirements via a single config file.

/r/JupyterNotebooks
https://redd.it/usl77o
Different foreignkey by condition in one model

Hi, I have a website that has a student and a teacher side. As a teacher you can track students progress in an elearning platform. There are 4 different ways that you can track a student.

Quiz, Fillinblanks, Read the chapter, Watched the video. (Each represents a model)

​

I want to make a model that lets the teacher assign homework for the student. I want to be able to make a model that is different depending on which homework you assign (Quiz, Fillinblanks etc..)

​

So if the teacher wants to assign a quiz and a watched the video for chapter 3.1 I want the model to do two rows. One for the quiz and one for the video, linked with foreign keys to the respective model so you track if the homework is done.

​

Is there an easy way to do this without using 8 tables for all of it. I read up on generic relations but I can't really figure out how to apply that to this situation.


Thanks for any help.

/r/django
https://redd.it/ut15qt
Jupyter notebook doesnt show output

so when i use python and try to run a cell more than once once a star (*) appears in the cell number and no output is given. i then have to either delete the cell or create a new file cuz i have no idea how to fix it

/r/JupyterNotebooks
https://redd.it/urrjtp
Understanding Flask authentication, authorisation, session management

### What I do?

A `User` model, most important part of my application usually connected to dozens of other models.

> User enters their unique username and password in a form on /register endpoint and submits.

The information submitted by user is recieved at backend.

I hash the password using `bcrypt` and save it in `password_hash` field.

> For /login I match user password hash with the saved hash.

I use Flask-Login which is a "user session management" library according to documentation.

I add @login_required to routes I need user to be authenticated.

### My burning questions

- What is authentication part of this flow and what is authorisation part?

- What is this "flow" called? Traditional...?

- What is Flask-login doing exactly? What happens if I don't use it?

- I am handling login/signup part almost manually, I'd like to do session part too, how does that work?

- My "API endpoints" are where I recieve json data and return jsonify data and it works fine with the same setup. So why do "APIs need different way to auth/auth"?
Is this because "browser is sending the cookie containing session info"?

- What is the right way to do auth/auth in an application which will be accessed by browsers (both template rendered views and endpoints)

/r/flask
https://redd.it/ut2xbs