Python Daily
2.57K subscribers
1.48K photos
53 videos
2 files
38.8K links
Daily Python News
Question, Tips and Tricks, Best Practices on Python Programming Language
Find more reddit channels over at @r_channels
Download Telegram
Flask apache hello world

I have an amazon aws server and was attempting to use flask to do a simple hello world on the server.

I have tried a few options listed at http://flask.pocoo.org/docs/0.12/deploying/ and can't seem to get any of them to work and I'm not entirely sure why. I also can't seem to find a simple hello world tutorial showing what I am trying to do.

So my question is what is the simplest way to have my server when accessed through a web browser display "Hello World"

Note the script is called hello_world.py: https://pastebin.com/30nutV4c

/r/flask
https://redd.it/7dbo3x
Flask, Docker + Google Cloud Platform

Hey guys,

I'm currently working on a pretty basic dockerized Flask application that consists of three containers, one for nginx, postgres and the flask_app itself. Everything works fine locally so no problems there what so ever. The point of the project however is to deploy such an application across some cloud platforms in a scalable way, enter Google Cloud Platform (gcp).

I have a cluster deployed on gcp and want to deploy to it. Instead of using a postgres container now (as I do locally) I've created a PostgreSQL db on gcp that I can use across my application. I've pushed my docker images sans the postgres image to the container registry and then I attempt to deploy using a deploy.yml (https://gist.github.com/tnolan8/b608c77ca4dff70bb48f8ae88408ff85) file. This is where I'm running into issues.

I'm using Flask-SqlAlchemy within the application to connect with my db, but no matter what connection string I seem to use I can't get the db to work with my application. I figure it must be something I'm doing incorrectly with my deploy.yml file and/or my connection string I'm setting in my app config for SQLALCHEMY_DATABASE_URI. What should I be setting this variable to? I'm relatively new to gcp and Kubernetes in general and would really appreciated any help/examples people may have.

Thank you!



/r/flask
https://redd.it/7d4c2c
Are you still on Python2? What is stopping you moving to Python3?

Any comments or links welcome. I'm trying to understand what the barriers are that keep us on Python2

/r/Python
https://redd.it/7dcgnq
javascripthon 0.8 released

Hello,

i'm pleased to announce a new release of javascripthon, the lean Python
to ES6 JavaScript translator. New in this release:

- add support for ``except`` sections with more than one exception
type and arbitrary exception variable name. Thanks to @devanlai;
- dict keys conversion fixes;
- enable ``--inline-map`` when translating a string with ``-s``;

See https://github.com/azazel75/metapensiero.pj for more info

cheers,

Alberto


/r/Python
https://redd.it/7dcpoy
[AF] Flask CRUD app.

Start off by saying I'm new to both Python and Flask. I've some programming and scripting experience, but was asked to learn Python so I could maintain a few sites my team uses.

I started by doing a search on how to get started with Flask and landed [here](https://scotch.io/tutorials/getting-started-with-flask-a-python-microframework). I was able to get everything installed and the basic "hello world" stuff going just fine. But it all came crashing down in [part 2](https://scotch.io/tutorials/build-a-crud-web-app-with-python-and-flask-part-one).

At this point, my code is basically copy/pasted from the [source](https://github.com/scotch-io/python-flask-crud-1), but am continually getting errors having to do with the blueprints. Here are my requirements and trace. Any help you good folks could give would be greatly appreciated. I have a feeling this is important...


(crud) C:\Users\xxxxx\Desktop\projects>pip freeze
alembic==0.9.6
click==6.7
dominate==2.3.1
Flask==0.12.2
Flask-Bootstrap==3.3.7.1
Flask-Login==0.4.0
Flask-Migrate==2.1.1
Flask-SQLAlchemy==2.3.2
Flask-WTF==0.14.2
itsdangerous==0.24
Jinja2==2.10
Mako==1.0.7
MarkupSafe==1.0
mysqlclient==1.3.12
python-dateutil==2.6.1
python-editor==1.0.3
six==1.11.0
SQLAlchemy==1.1.15
visitor==0.1.3
Werkzeug==0.12.2
WTForms==2.1


(crud) C:\Users\xxxxxx\Desktop\projects>flask run
c:\users\xxxxxx\envs\crud\lib\site-packages\flask_sqlalchemy\__init__.py:794: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future. Set it to True or False to suppress this warning.
'SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and '
Traceback (most recent call last):
File "c:\users\xxxxxx\appdata\local\programs\python\python36-32\Lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\users\xxxxxx\appdata\local\programs\python\python36-32\Lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\xxxxxx\Envs\crud\Scripts\flask.exe\__main__.py", line 9, in <module>
File "c:\users\xxxxxx\envs\crud\lib\site-packages\flask\cli.py", line 513, in main
cli.main(args=args, prog_name=name)
File "c:\users\xxxxxx\envs\crud\lib\site-packages\flask\cli.py", line 380, in main
return AppGroup.main(self, *args, **kwargs)
File "c:\users\xxxxxx\envs\crud\lib\site-packages\click\core.py", line 697, in main
rv = self.invoke(ctx)
File "c:\users\xxxxxx\envs\crud\lib\site-packages\click\core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "c:\users\xxxxxx\envs\crud\lib\site-packages\click\core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "c:\users\xxxxxx\envs\crud\lib\site-packages\click\core.py", line 535, in invoke
return callback(*args, **kwargs)
File "c:\users\xxxxxx\envs\crud\lib\site-packages\click\decorators.py", line 64, in new_func
return ctx.invoke(f, obj, *args[1:], **kwargs)
File "c:\users\xxxxxx\envs\crud\lib\site-packages\click\core.py", line 535, in invoke
return callback(*args, **kwargs)
File "c:\users\xxxxxx\envs\crud\lib\site-packages\flask\cli.py", line 423, in run_command
app = DispatchingApp(info.load_app, use_eager_loading=eager_loading)
File "c:\users\xxxxxx\envs\crud\lib\site-packages\flask\cli.py", line 152, in __init__
self._load_unlocked()
File "c:\users\xxxxxx\envs\crud\lib\site-packages\flask\cli.py", line 176, in _load_unlocked
self._app = rv = self.loader()
File "c:\users\xxxxxx\envs\crud\lib\site-packages\flask\cli.py", line 237, in load_app
rv = locate_app(self.app_import_path)
File "c:\users\xxxxxx\envs\crud\lib\site-packages\flask\cli.py", line 90, in locate_app
__import__(module)
File "C:\Users\xxxxxx\Desktop\projects\run.py", line 6, in <module>
app = create_app(config_name)
File "C:\Users\xxxxxx\Desktop\projects\app\__init__.py", line 29, in create_app
from .admin import admin as admin_blueprint
ImportError: cannot import name 'admin'

/r/flask
htt
ps://redd.it/7df66j
Why did Python only become dominant recently?

Python came out in 1991, which is earlier than PHP, Java, Javascript, which all came out around mid 1990s. People tend to see PHP as old tech, but Python is even older.

Yet Python never had [huge popularity](https://trends.google.com/trends/explore?date=all&q=python) until the [sudden growth in the early 2010s](https://stackoverflow.blog/wp-content/uploads/2017/09/projections-1-1400x1200.png). What caused this sudden increase in popularity?

/r/Python
https://redd.it/7deptd
Best way to pass a ton of command line arguments into a Python application?

I'm writing an application with a bunch of classes that interact with each other, and the client would like to be able to specify parameters through the command line. For example `app num_people=1000 realtime=True outputdir='my/home/dir'`, but with far more options. The options will be in a variety of classes, and will have defaults if nothing is passed in.

What is the best way to do this in Python 3? I know about `argparse` but it seems like a potential framework I'll use to answer this question, not the actual solution.

/r/Python
https://redd.it/7de04d
Can we make djangopackages.org better ?

Hello !

I've been using Django for a while, and I still sometimes stumble upon an amazing Django package. Usually through an answer from SO*, or from a slightly off google search that returned an interesting result. Shouldn't I know all the top packages by now ?

Djangopackages.org is supposed to be the ideal tool to quickly lookup and select the ideal package to solve your problem. Even though it's got hundreds of packages listed, I feel like we could improve upon it greatly.

A key number is the "# using this", which is supposed to indicate how many projects are using the package at the moment. Even in the "CMS" category, one of the largest ones, the top package, Django-CMS, reports only 160 users! Django-CMS has twice as many contributors, and over 5000 stars on github.

The UX is ageing as well. It's not an easy site to navigate, and the relevant information doesn't pop up very clearly.

What are the issues you have with finding and choosing packages? What ideas would you have to improve the site?

**If you could build the backlog of djangopackages.org, what would be your priority?**

---

^* ^Cannot ^say ^the ^name ^otherwise ^the ^post ^gets ^automodded, ^but ^you ^may ^have ^guessed ^this ^is ^the ^main ^website ^on ^which ^devs ^ask ^questions

/r/django
https://redd.it/7dg0tn
evolution strategies for cartpole

my simple and straightforward [implementation](https://github.com/mynameisvinn/CartpoleES) of evolution strategies applied to the game of cartpole. hope you find it helpful!

/r/Python
https://redd.it/7dhqa3
Python package for defining, recoding, and validating table schemas in pandas using a SQLAlchemy-like syntax.

This is a VERY young attempt at solving a recurrent problem I have that I have not found a solution for that "made sense" to me and my work flow.

I need to load, recode, and validate tables all day everyday. Sometimes its simple and you can `pandas.read_table()` and all is good. But sometimes you have a 400 column long RedCap data dump that is complected af and you need to develop your recoding logic through an iterative process.

This is an attempt of mine to apply a sort of "test driven development" approach to data cleaning. Define a representation of your ideal form of your data. Then use this to validate your input table. It WILL fail. Add recoding functions until your validations pass. Then you can pass this representation into your loading functions, or whenever your program gets a version of this type of data from another process to do sanity checks before going further.

Please take a look and offer thoughts/advice.

https://github.com/xguse/table_enforcer

/r/Python
https://redd.it/7dg00l
Change to django's default id field in 1.11

Hi, I upgraded to django 1.11 and when I use `MyModel.objects.create(id='some_id', **kwargs)` now, the object gets created with an id of `some_id`, where before django's default `AutoField` id field would generate the id automatically.

can anyone confirm this change happened? (I don't mind not passing id, just making sure the version upgrade is the cause of this change)

/r/django
https://redd.it/7djmlb
Help with coming up with a good case to switch from Flask to Django

Hi everyone. So I have inherited a relatively large multi-tenant SAAS application (in terms of business logic) built in Flask.

I have not gone too deep into the code but have started adding features already and have noticed a lot of gotchas already that could've been easily avoided with Django. Also, as you would imagine, a lot of implementation design that would've been done better in Django (auth, permissions, to name a few).

Talking with the business regarding direction of the app suggests that we will later want to have object level permissions, better handling of groups and users, integrations with 3rd party APIs, creating our own RESTful service, etc. Such features I know are already integrated quite well in both Django's batteries and library ecosystem.

My current perspective is to take advantage of a lot of best practice built in Django and the cohesiveness of its ecosystem and avoid a lot of needless library integration and reinventing-the-wheel down the line as this app will only get more complex.

I understand this will require a lot of work upfront and that equates to development costs that could've been spent on new features and this is where I am looking for thoughts and advice from you.

Have you done something like this before?
What was your approach?
What are questions that I need to consider?
What's the best way this can be done incrementally?
Do you think the pros outweigh the cons?
How did you convince the business to pursue the switch?
Is this even worthwhile or am I missing an important point?

/r/django
https://redd.it/7dl77c
Is it useful to install Anaconda on linux, when python and most packages can be installed via package managers ?

My main usage of python for the moment are scripting, and machine learning (using frameworks as tensorflow and keras)

/r/Python
https://redd.it/7dls42
Own decorator getting arguments from another line after - @app.route(rule, *args) - is it possible?

I want to store all functions from my flask app, so I made my own decorator inside Blog class and calling it as follows. It works well, but I also want to store these arguments (rule and methods) from @app.route inside my Blog class. Code as follows:

@Blog.register() # my own generator
@app.route(rule="/api/login", methods=["POST"])
def login():
if request.method == "POST":
data = my_logging_func()
return jsonify(data)

Is there a way to get @app.route params in @Blog.register() as it wraps over it?


/r/flask
https://redd.it/7d3wbt