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
Saleor vs Oscar vs Home-made

Hello !

I've built my online shop without a dedicated e\-commerce library, just plugging into Stripe manually to deal with sales.

I'm beginning to feel the limits of this approach, especially with regards to integrating my site with third\-party services : stripe, google analytics, paypal, zapier, ...

For example, I'd like to activate 3D secure on my site, and add paypal support. It would probably be very easy to do with Saleor and Oscar, but I have to do it manually as of now. The downside to implementing these frameworks is that I've already got a working sales funnel, and I'm afraid of the amount of work required to fit the frameworks to my existing setup.

As a solo dev, do you think I should keep going with the manual approach, or do you think Saleor and Oscar would be good ways to upgrade my site ? What is your experience with them ?

/r/django
https://redd.it/8p1h97
[D] Dedicated to all those researchers in fear of being scooped :)

/r/MachineLearning
https://redd.it/8p169l
[JupyterLab] How to Run R Code AND Python Code in Same Notebook?

I am trying to run some python code, then carry those created objects through some R code, then back to python within the same notebook. I know it was possible in Jupyer Notebook as I have seen many tutorials on how to do it.
Jupyter notebook used to have things like rpy2 but that does not seem to work anymore. Does anyone know how to accomplish this in JupyterLab in anaconda?

Thanks in Advance!

/r/IPython
https://redd.it/8p4m0m
Login through api

Hello guys what would be the best way to login through a api and to keep the user logged in like flask-login do and that can offer the best protection for the api

/r/flask
https://redd.it/8p5cnn
Flask in Docker, some problems here.

Hello everyone,
once again i have a problem with a docker app. To be more precise i want to learn python flask development, so i created an docker image, here it is:
`FROM python:alpine`
`WORKDIR /app`
`COPY ./app/requirements.txt .`
`RUN pip install --no-cache-dir -U -r requirements.txt`
Pretty basic. Just installs flask into my container.
Then i have the following docker\-compose file:
`version: '3'`
`services:`
`flaskapp:`
`build: .`
`container_name: flaskapp`
`volumes:`
`- $PWD/app:/app`
`environment:`
`- FLASK_APP=app.py`
`- FLASK_SETTINGS=config/config.py`
`ports:`
`- "5000:5000"`
`command: flask run`
As you see, there are two environment vars that i want to pass to my container. First, the actual flask app that is in the /app folder. Then, the localtion of my config file which is in the /config directory.
Here is my app.py file:
`from flask import Flask`
`import os`
`app = Flask(__name__)`
`app.config.from_envvar('FLASK_SETTINGS')`
`@app.route('/')`
`def index():`
`return 'Index Page'`
Here is the config file:
`DEBUG = True`
`HOST = '0.0.0.0'`
So now to the actual misbehavior, when i start the container i get the following:
`docker-compose up`
`Starting flaskapp ... done`
`Attaching to flaskapp`
`flaskapp | * Serving Flask app "app.py"`
`flaskapp | * Environment: production`
`flaskapp | WARNING: Do not use the development server in a production environment.`
`flaskapp | Use a production WSGI server instead.`
`flaskapp | * Debug mode: off`
`flaskapp | * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)`
The environment variable FLASK\_APP is being read correctly, flask detects its ("`* Serving Flask app "`[`app.py`](https://app.py/)`"`"), but the config file isnt loaded ("`Debug mode: off`"), also `HOST = '`[`0.0.0.0`](https://0.0.0.0/)`'` is not set because i cant reach the app with my browser.

I assume that i have some error in my [app.py](https://app.py), but iam not sure.

Can you guys see any errors in my set up here? Wanted to learn flask and now already stuck with the basics :(

Btw, i also tried it without docker (same python files), also no luck.

Thanks in advance, have a nice day everyone!

/r/flask
https://redd.it/8p2ygx
Advice on IDE or editor for Django

I'm new at Django and currently working on a large personal project (iOS chat app with django backend). I'm using Webfaction hosting, and right now I'm just logging in through ssh, using vim to edit files, then running and opening up the error log file to debug one error at a time. Is there better way of doing this? It'd be nice to be able to use a Python "compiling" editor and run the code immediately without having to ssh files back and forth.

/r/django
https://redd.it/8p6zoa
Easiest way to query a model's property?

In my user model, I have a paid member ("premium") property that checks Stripe and returns True or False.

This is fine for 90% of my site and locking away content, but there are also times when I need to sort users by premium status. Any suggestions for how to do this?

I saw something along the lines of this:

class UserProfile(models.model):
premium_field = models.BooleanField(db_column="premium")

@property
def premium(self):
if stripe.paid():
return True
else:
return False


But it looks like I might need a getter function as well? Hopefully I'm on the right track -- I just don't want to migrate or push changes unless I know I have it right. Thanks!



/r/djangolearning
https://redd.it/8p57w5
Is it a good idea to use a mixin for a multi-value field?

Lets say that I have a model called 'Movie' and I want 'Movies' to have a spot to remember all the genres it belongs to (Horror, Suspense, Funny, Romance, etc... ). It seems like there are a few options. I could make a single field that stores a JSON string that holds genres as keys and booleans as values (Bad Idea). I could create a Boolean field in 'Movie' for each of the genres. But that makes for a lot of fields in a single model. Or I could make a mixin called 'GenreMixin' with a boolean field for each genre and have 'Movie' inherit from it.


What is the best practice, what will lead to the easiest to maintain down the road?

/r/djangolearning
https://redd.it/8p538x
[AF] How to run a function after returning response (AWS Lambda)

Hey everyone! I'm using zappa to run a simple ffmpeg transcode function on Lambda with Flask. While Lambda functions can run for up to 5 minutes, the problem I'm running into is that Amazon's API Gateway times out after 30 seconds so I'm unable to just wait for ffmpeg to finish before returning a response.

I'm looking for a way to return a response immediately from my Flask function and then continue running my ffmpeg function in the background. (The Flask response will contain a JSON payload with the S3 url that the finished ffmpeg job will upload to.)

I've tried using `threading.Thread` but it doesn't appear to stay alive after my Flask function returns. Thoughts/ideas? Thank you for your help!

/r/flask
https://redd.it/8p78ev
How do you use Python to automate something in your daily life?

This question seems to produce new and unique responses each time it is asked, so why not give it another go? I’d love to hear how you use Python to automate something to save you time!

/r/Python
https://redd.it/8p7zjf
[AF] How to sort SQLAlchemy query by number of many to many relationships

Hello!

I have two tables which I've simplified below. A post model and a post likes model. When I want to create a like on a post, I create an instance of a post like which holds a backreference to the post in question.

I would like to perform a query that will grab all my posts and sort them by number of likes. However, because I'm still a bit green when it comes to SQLAlchemy, I'm not sure how to sort by number of many to many relationships (self\_likes).

class PostLike(db.Model):
post_id = db.Column("post_id", db.Integer, db.ForeignKey("post.id"),
primary_key=True)

class Post(db.Model):
_tablename_ = "post"
id = db.Column(db.Integer, primary_key=True)
self_likes = db.relationship("PostLike", backref="self_likes", lazy="dynamic", foreign_keys="PostLike.post_id")

Any help would be greatly appreciated!

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