Deployment best practices for secret key, environment variables, etc
I just spent days - DAYS - on my first real AWS EC2 deployment, all because I was setting environment variables on the production server and apparently that doesn't work. I finally figured it out and was able to deploy with my key and passwords hard-coded into my settings.py on the production server which, I assume, is not something I should be doing? But then Django docs say to use env vars or to import from a file, but that sounds just as insecure as hard coding it into settings.py, so maybe I'm overthinking this.
What the standard practice in production? Where do you put the secret key and, say, the email server password? When I search for environment variables + AWS EC2 there's a whole bunch of results I don't understand involving startup scripts and whatnot, which I'm not using at this point.
/r/djangolearning
https://redd.it/6a7wfy
I just spent days - DAYS - on my first real AWS EC2 deployment, all because I was setting environment variables on the production server and apparently that doesn't work. I finally figured it out and was able to deploy with my key and passwords hard-coded into my settings.py on the production server which, I assume, is not something I should be doing? But then Django docs say to use env vars or to import from a file, but that sounds just as insecure as hard coding it into settings.py, so maybe I'm overthinking this.
What the standard practice in production? Where do you put the secret key and, say, the email server password? When I search for environment variables + AWS EC2 there's a whole bunch of results I don't understand involving startup scripts and whatnot, which I'm not using at this point.
/r/djangolearning
https://redd.it/6a7wfy
reddit
Deployment best practices for secret key,... • r/djangolearning
I just spent days - DAYS - on my first real AWS EC2 deployment, all because I was setting environment variables on the production server and...
Speedml is a Python package to speed start machine learning projects.
https://github.com/Speedml/speedml
/r/Python
https://redd.it/6aa57b
https://github.com/Speedml/speedml
/r/Python
https://redd.it/6aa57b
GitHub
GitHub - Speedml/speedml: Speedml is a Python package to speed start machine learning projects.
Speedml is a Python package to speed start machine learning projects. - Speedml/speedml
Looking for feedback on my first tutorial: How to deploy Django app on AWS (with Elastic Beanstalk)
https://codepal.herokuapp.com/deploying-django-app-on-aws-using-elastic-beanstalk/
/r/django
https://redd.it/6a6a1h
https://codepal.herokuapp.com/deploying-django-app-on-aws-using-elastic-beanstalk/
/r/django
https://redd.it/6a6a1h
CodePal
How to deploy a Django app on AWS (with Elastic Beanstalk)
This tutorial is walk-through of how to deploy a Django application to AWS Elastic Beanstalk (with Postgres).
Worth the switch to Pycharm?
I've been using Emacs for a while to do things like stats in R (ESS), organizing my life (org-mode), and writing papers (auctex). So I've got quite a bit of investment in Emacs. I'm not a super-user by any means, but I can use it pretty efficiently.
Now that I'm starting to do a lot more Python development, I've heard over and over again how amazing Pycharm is. I have access to the full edition, so I'll be able to use it to its full potential. I am wondering about a few things, though, as well as the general "is it worth it?" question.
* How good is IdeaVim? I use spacemacs in Emacs, so I'm used to bopping around inside and between files with vim-style shortcuts.
* Is there an easy way to sync settings between machines? I do development on 2-3 different computers (home, work, laptop), and I'd like to keep everything synced up between the three.
* What are the killer features I should switch for?
EDIT new question:
* Is it possible to have machine-specific settings in addition to syncing general settings? For example, my laptop is super small, so I usually use a slightly smaller font size there so I can see a bit more code.
* I also want to start using Python for more of my data analysis. Does Pycharm work well for that, or should I use a different package for the stats stuff?
Thanks y'all.
/r/Python
https://redd.it/6ac5pk
I've been using Emacs for a while to do things like stats in R (ESS), organizing my life (org-mode), and writing papers (auctex). So I've got quite a bit of investment in Emacs. I'm not a super-user by any means, but I can use it pretty efficiently.
Now that I'm starting to do a lot more Python development, I've heard over and over again how amazing Pycharm is. I have access to the full edition, so I'll be able to use it to its full potential. I am wondering about a few things, though, as well as the general "is it worth it?" question.
* How good is IdeaVim? I use spacemacs in Emacs, so I'm used to bopping around inside and between files with vim-style shortcuts.
* Is there an easy way to sync settings between machines? I do development on 2-3 different computers (home, work, laptop), and I'd like to keep everything synced up between the three.
* What are the killer features I should switch for?
EDIT new question:
* Is it possible to have machine-specific settings in addition to syncing general settings? For example, my laptop is super small, so I usually use a slightly smaller font size there so I can see a bit more code.
* I also want to start using Python for more of my data analysis. Does Pycharm work well for that, or should I use a different package for the stats stuff?
Thanks y'all.
/r/Python
https://redd.it/6ac5pk
reddit
Worth the switch to Pycharm? • r/Python
I've been using Emacs for a while to do things like stats in R (ESS), organizing my life (org-mode), and writing papers (auctex). So I've got...
I started building a Flask API service using Python 3.6 and I can't connect to the database. More info below
I have the following code for database connection:
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
In other part of the app I have some code for adding tables, etc.:
db.init_app(flask_app)
db.create_all()
db.session.commit()
This is the error I'm getting: `ModuleNotFoundError: No module named 'MySQLdb'
What's going on here? I'm positive I have `MySQL` on my Mac. Is this because I'm using Python 3?
Thanks in advance!
/r/flask
https://redd.it/6a35tn
I have the following code for database connection:
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
In other part of the app I have some code for adding tables, etc.:
db.init_app(flask_app)
db.create_all()
db.session.commit()
This is the error I'm getting: `ModuleNotFoundError: No module named 'MySQLdb'
What's going on here? I'm positive I have `MySQL` on my Mac. Is this because I'm using Python 3?
Thanks in advance!
/r/flask
https://redd.it/6a35tn
reddit
I started building a Flask API service using Python 3.6... • r/flask
I have the following code for database connection: from flask_sqlalchemy import SQLAlchemy db = SQLAlchemy() In other part of the app I...
Project-based tables and Django
Hi everyone,
I am looking for some suggestion/input regarding how to structure the database for a web-based application I will need to develop in the following months.
Basically I will need to develop an application to organize technical information (cable connections, tags, I/O boards, etc). The main issue is that this documentation is project-based, and I'd like to avoid to have everything merged together (i.e. I don't want to have a single table with all I/O boards for all the projects, as I'll have to filter by project in any query I do, and the table size will quickly grow out of control).
My idea is to create a different DB everytime a new project is started, and to populate said DB with the required empty tables ("bootstrapping a project"). Then I'd like to access the various projects via URLs (like /myapp/project1/ will "open" project1).
Probably the easiest thing would be to just create a different instance of the web app for each project, but that would make more difficult the creation of a new project (instance a new container/VM/whatever for the app...), as well as "sharing data" functions (like "copy all this I/Os from project A to B"). So I'd like to avoid this path.
Is there a best practice for this, or do you have any suggestion from your experience? I know that this is a Django subreddit but... perhaps Django is not the best candidate for something like that, and is better to go with something more... barebone (e.g. flask)?
Thanks! :)
/r/django
https://redd.it/6adio8
Hi everyone,
I am looking for some suggestion/input regarding how to structure the database for a web-based application I will need to develop in the following months.
Basically I will need to develop an application to organize technical information (cable connections, tags, I/O boards, etc). The main issue is that this documentation is project-based, and I'd like to avoid to have everything merged together (i.e. I don't want to have a single table with all I/O boards for all the projects, as I'll have to filter by project in any query I do, and the table size will quickly grow out of control).
My idea is to create a different DB everytime a new project is started, and to populate said DB with the required empty tables ("bootstrapping a project"). Then I'd like to access the various projects via URLs (like /myapp/project1/ will "open" project1).
Probably the easiest thing would be to just create a different instance of the web app for each project, but that would make more difficult the creation of a new project (instance a new container/VM/whatever for the app...), as well as "sharing data" functions (like "copy all this I/Os from project A to B"). So I'd like to avoid this path.
Is there a best practice for this, or do you have any suggestion from your experience? I know that this is a Django subreddit but... perhaps Django is not the best candidate for something like that, and is better to go with something more... barebone (e.g. flask)?
Thanks! :)
/r/django
https://redd.it/6adio8
reddit
Project-based tables and Django • r/django
Hi everyone, I am looking for some suggestion/input regarding how to structure the database for a web-based application I will need to develop in...
Automate Everything with Python - Question
Hi Ya'll,
I'm learning Python from Automate the Boring Stuff. My first project is to download episodes of this podcast I like. Right now when I run the program is downloads all the HTML from the 'url.' Where am I going wrong?
Next question. What it is supposed to do next is Click on all the links that say "Download this Episode." I have that bit of code included in the below but it doesn't seem to be working yet. Also, any tips for someone learning how to work with python would be appreciated!
Below is the python script:
https://drive.google.com/open?id=0B_w5K7I4N0d3a0JReW1QRUNPUXM
/r/Python
https://redd.it/6ad823
Hi Ya'll,
I'm learning Python from Automate the Boring Stuff. My first project is to download episodes of this podcast I like. Right now when I run the program is downloads all the HTML from the 'url.' Where am I going wrong?
Next question. What it is supposed to do next is Click on all the links that say "Download this Episode." I have that bit of code included in the below but it doesn't seem to be working yet. Also, any tips for someone learning how to work with python would be appreciated!
Below is the python script:
https://drive.google.com/open?id=0B_w5K7I4N0d3a0JReW1QRUNPUXM
/r/Python
https://redd.it/6ad823
Using PreFetch with DRF ViewSets to include a @property on a model that relies on reverse foreign keys.
It took me entirely too long to figure this out, so thought I would share in case others are running into the same thing. Note that I attempted to use a OneToOne, but because not every Model B can relate to a Model A, and it throws duplicate errors on Nulls... I couldn't.
Model B has a FK to Model A.
Model A has a @property to obtain a field from Model B from a single model instance. In this scenario, I know there will only be one, so I go get the first value only.
@property
get_model_B_field(self):
b = self.modelB_set.values('field').all()
if b:
return b[0].field
Of course, including this in the serializer quickly creates the N+1 problem, as Django will re-query the database for each Model A in the queryset. As I have several properties like this across a variety of models, the problem grew exponentially until I had thousands of queries running and 12+ seconds to load the api page. P.S. I highly recommend using [Django Debug Toolbar](https://django-debug-toolbar.readthedocs.io/en/stable/).
First attempt was to use prefetch_related as such in the ViewSet which calls the serializer:
queryset=ModelA.objects.prefetch_related('modelB_set').all()
Still N+1
I went back to the property and attempted to remove the "values" aspect, and also make use of the first() function.
@property
get_model_B_field(self):
b = self.modelB_set.first()
if b:
return b.field
Still N+1
Then I tried using the new Prefetch object on my view's queryset, as such:
queryset=ModelA.objects.prefetch_related(Prefetch('modelB_set',queryset=ModelB.objects.all()))
Still N+1
Finally, I read the bug report from another user indicating first() wasn't respecting the prefetch, to realize that in order for that to happen, you must explicitly set an order on the queryset in the PreFetch()
queryset=ModelA.objects.prefetch_related(Prefetch('modelB_set',queryset=ModelB.objects.order_by('field').all()))
Finally, down to 7-8 (from 5000+) queries for a rather large API returning data from across multiple models, many of which are reverse FK lookups in about 1 second. If others have a more elegant solution, I'd love to hear it. My only other option was going to be attempt to use Nested Serializers, but I didn't want to nest all of ModelB inside ModelA, and I didn't like the idea of creating multiple serializers against ModelB to just handle different field combinations. Now, I can have all my properties in one place (the model), and include the fields individually on the API as needed.
/r/django
https://redd.it/6aexjt
It took me entirely too long to figure this out, so thought I would share in case others are running into the same thing. Note that I attempted to use a OneToOne, but because not every Model B can relate to a Model A, and it throws duplicate errors on Nulls... I couldn't.
Model B has a FK to Model A.
Model A has a @property to obtain a field from Model B from a single model instance. In this scenario, I know there will only be one, so I go get the first value only.
@property
get_model_B_field(self):
b = self.modelB_set.values('field').all()
if b:
return b[0].field
Of course, including this in the serializer quickly creates the N+1 problem, as Django will re-query the database for each Model A in the queryset. As I have several properties like this across a variety of models, the problem grew exponentially until I had thousands of queries running and 12+ seconds to load the api page. P.S. I highly recommend using [Django Debug Toolbar](https://django-debug-toolbar.readthedocs.io/en/stable/).
First attempt was to use prefetch_related as such in the ViewSet which calls the serializer:
queryset=ModelA.objects.prefetch_related('modelB_set').all()
Still N+1
I went back to the property and attempted to remove the "values" aspect, and also make use of the first() function.
@property
get_model_B_field(self):
b = self.modelB_set.first()
if b:
return b.field
Still N+1
Then I tried using the new Prefetch object on my view's queryset, as such:
queryset=ModelA.objects.prefetch_related(Prefetch('modelB_set',queryset=ModelB.objects.all()))
Still N+1
Finally, I read the bug report from another user indicating first() wasn't respecting the prefetch, to realize that in order for that to happen, you must explicitly set an order on the queryset in the PreFetch()
queryset=ModelA.objects.prefetch_related(Prefetch('modelB_set',queryset=ModelB.objects.order_by('field').all()))
Finally, down to 7-8 (from 5000+) queries for a rather large API returning data from across multiple models, many of which are reverse FK lookups in about 1 second. If others have a more elegant solution, I'd love to hear it. My only other option was going to be attempt to use Nested Serializers, but I didn't want to nest all of ModelB inside ModelA, and I didn't like the idea of creating multiple serializers against ModelB to just handle different field combinations. Now, I can have all my properties in one place (the model), and include the fields individually on the API as needed.
/r/django
https://redd.it/6aexjt
Asyncio event loop written in Rust language
I'd like to announce new event loop, written in Rust language.
https://github.com/PyO3/tokio
It is still in alpha stage. It provides most of asyncio event loop apis, except udp. TCP api is more or less stable, Aiohttp tests pass with tokio loop (~1800 tests). I am planing to run more tests from other libraries.
Performance wise it should be close to uvloop.
But main motivation behind this project is to be able to mix Rust code with Python. Internal implementation still requires
more thinking, but it is already possible to to wait for python task/future completion in rust code and opposite.
Project is still in early stage of development, if anyone interested, everyone welcome to join.
/r/Python
https://redd.it/6ael2m
I'd like to announce new event loop, written in Rust language.
https://github.com/PyO3/tokio
It is still in alpha stage. It provides most of asyncio event loop apis, except udp. TCP api is more or less stable, Aiohttp tests pass with tokio loop (~1800 tests). I am planing to run more tests from other libraries.
Performance wise it should be close to uvloop.
But main motivation behind this project is to be able to mix Rust code with Python. Internal implementation still requires
more thinking, but it is already possible to to wait for python task/future completion in rust code and opposite.
Project is still in early stage of development, if anyone interested, everyone welcome to join.
/r/Python
https://redd.it/6ael2m
GitHub
GitHub - PyO3/tokio: Asyncio event loop written in Rust language
Asyncio event loop written in Rust language. Contribute to PyO3/tokio development by creating an account on GitHub.
Testing serialization independently from views (DRF)
How would one go about testing serialization independent of my views?
In other words, just hardcoding a Django model object and using the serializer.
Problem is that HyperLinkedIdentityField is throwing an error saying to add the request to the context (I am using HyperlinkedModelSerializers). I do this in my views, but I don't want to introduce views here. If I simulate a post request, then I'll have to go through my views.
Is there a way around this?
I still consider myself a noob with testing and have never done testing with API's beyond manually testing my API endpoints, so I'd appreciate any general advice.
Thanks!
/r/django
https://redd.it/6afevz
How would one go about testing serialization independent of my views?
In other words, just hardcoding a Django model object and using the serializer.
Problem is that HyperLinkedIdentityField is throwing an error saying to add the request to the context (I am using HyperlinkedModelSerializers). I do this in my views, but I don't want to introduce views here. If I simulate a post request, then I'll have to go through my views.
Is there a way around this?
I still consider myself a noob with testing and have never done testing with API's beyond manually testing my API endpoints, so I'd appreciate any general advice.
Thanks!
/r/django
https://redd.it/6afevz
reddit
Testing serialization independently from views (DRF) • r/django
How would one go about testing serialization independent of my views? In other words, just hardcoding a Django model object and using the...
Creating CRUD Interface with SQLAlchemy
Im in the middle of doing a small project. Right now, I have a flask application that is connecting to a SQLAlchemy database and Im able to use a form to add new entries to that database. I also have a page [here](http://imgur.com/a/PJ6fK) that displays the values that are being held by the SQL database.
However, now I want to turn the page that is showing the data into a CRUD interface so i am able to not so much create new entries but to read, update current data thats being stored and delete entries as well. (More like a RUD design :P)
I have looked all over the web for a simple example of someone doing this in SQLAlchemy & Flask but haven't really come across anything decent. Does anyone know of any examples I can look at to do this simply? I've looked at the SQLAlchemy docs but it doesnt really show how to do it using Jinja templates and im relatively new to all this so need as much help as I can get.
/r/flask
https://redd.it/6adlzf
Im in the middle of doing a small project. Right now, I have a flask application that is connecting to a SQLAlchemy database and Im able to use a form to add new entries to that database. I also have a page [here](http://imgur.com/a/PJ6fK) that displays the values that are being held by the SQL database.
However, now I want to turn the page that is showing the data into a CRUD interface so i am able to not so much create new entries but to read, update current data thats being stored and delete entries as well. (More like a RUD design :P)
I have looked all over the web for a simple example of someone doing this in SQLAlchemy & Flask but haven't really come across anything decent. Does anyone know of any examples I can look at to do this simply? I've looked at the SQLAlchemy docs but it doesnt really show how to do it using Jinja templates and im relatively new to all this so need as much help as I can get.
/r/flask
https://redd.it/6adlzf
Imgur
Imgur: The most awesome images on the Internet
Imgur: The most awesome images on the Internet.
Python support is now stable in Visual Studio 2017
https://blogs.msdn.microsoft.com/pythonengineering/2017/05/10/python-now-stable-in-vs-2017/
/r/Python
https://redd.it/6ag8pq
https://blogs.msdn.microsoft.com/pythonengineering/2017/05/10/python-now-stable-in-vs-2017/
/r/Python
https://redd.it/6ag8pq
Question about Django Rest Auth and Users
I am using Django Rest Auth endpoints and DRF for learning. I created a basic To-Do app and it works just fine but after I have new users register, I would like them to be able to do basic CRUD operations on their own tasks.
Because I am using Django Rest Auth to register users, is there anything special I need to override? How would I go about achieving this goal?
I feel like this may be an easy problem to solve but I'm having trouble. I've tried adding to views.py
permission_classes = (IsAuthenticated,)
but does not work.
Thanks for any help!
/r/django
https://redd.it/6ahge2
I am using Django Rest Auth endpoints and DRF for learning. I created a basic To-Do app and it works just fine but after I have new users register, I would like them to be able to do basic CRUD operations on their own tasks.
Because I am using Django Rest Auth to register users, is there anything special I need to override? How would I go about achieving this goal?
I feel like this may be an easy problem to solve but I'm having trouble. I've tried adding to views.py
permission_classes = (IsAuthenticated,)
but does not work.
Thanks for any help!
/r/django
https://redd.it/6ahge2
reddit
Question about Django Rest Auth and Users • r/django
I am using Django Rest Auth endpoints and DRF for learning. I created a basic To-Do app and it works just fine but after I have new users...
62 video tutorials on Django by Max Goodridge
https://www.youtube.com/playlist?list=PLw02n0FEB3E3VSHjyYMcFadtQORvl1Ssj
/r/django
https://redd.it/6aiio0
https://www.youtube.com/playlist?list=PLw02n0FEB3E3VSHjyYMcFadtQORvl1Ssj
/r/django
https://redd.it/6aiio0
YouTube
Django Tutorials
Share your videos with friends, family, and the world
Example of CRUD with Flask to manage a contact list.
https://github.com/tanrax/flask-contacts
/r/flask
https://redd.it/6ai9eg
https://github.com/tanrax/flask-contacts
/r/flask
https://redd.it/6ai9eg
GitHub
GitHub - tanrax/flask-contacts: Example of CRUD with Flask to manage a contact list.
Example of CRUD with Flask to manage a contact list. - GitHub - tanrax/flask-contacts: Example of CRUD with Flask to manage a contact list.
Scaling Python/Flask Microservices with Kubernetes
http://blog.apcelent.com/scaling-python-microservices-kubernetes.html
/r/Python
https://redd.it/6ai6oo
http://blog.apcelent.com/scaling-python-microservices-kubernetes.html
/r/Python
https://redd.it/6ai6oo
reddit
Scaling Python/Flask Microservices with Kubernetes • r/Python
13 points and 2 comments so far on reddit
Python overtakes PHP on Stackoverflow
https://stackoverflow.blog/2017/05/09/introducing-stack-overflow-trends/?cb=1
/r/Python
https://redd.it/6ad0r0
https://stackoverflow.blog/2017/05/09/introducing-stack-overflow-trends/?cb=1
/r/Python
https://redd.it/6ad0r0
Stack Overflow Blog
Introducing Stack Overflow Trends - Stack Overflow Blog
On a typical day, developers ask over 8,000 questions on Stack Overflow about programming problems they run into in their work. Which technologies are they asking about, and how has that changed over time?