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
What special features or batteries does Django ship with that Flask doesn't has?

I've always used only flask for all the web apps I've built and surprisingly, I've never needed something like django. For database interaction, I always had `sqlalchemy`, for other stuff like the google api client library or something, I usually just `pip install` stuff that I need.

As a result, I've never felt the need to look much deeper into something like django. Nevertheless, since django is so much popular than flask and everyone seem to sing praises of it, I'm curious to know what all batteries are included in it that makes it more "fully featured" as a lot of developers say, when compared to flask.

/r/Python
https://redd.it/5l353d
Python function output into a django model

I am fairly new to django, and am having some trouble getting the output from a function into a model where it will be stored.

The idea is that the list of list function output is a name and a id string, and will be stored as values in the db with the default auto generated primary key.

[['t5.lg.ubuntu.template', '2c91808656b597ff0156ba98b79901f9'], ['DigitalOcean Ubuntu 14.04 Large FRA', '4028818650d4aca10150d4bf63470003'], ['DigitalOcean Ubuntu 14.04 Large NYC2', '4028818650d4aca10150d4bf63470004'], ['DigitalOcean Ubuntu 14.04 XLarge LON', '4028818650d4aca10150d4bf63470005']]

The functionality that i am looking for are fields in the database that I can periodically update by calling the function with any new values and updating the model.

This is my model that I currently have.

class dchqServerBlueprints(models.Model):
blueprintName = models.CharField(max_length=255)
blueprintId = models.CharField(max_length=255)

def __str__(self):
return (self.blueprintId, self.blueprintName)

After a lot of googling, I am pretty stuck on how to go about this. I've seen some references to serializing a list into JSON and storing that JSON in the database, but that seems a little excessive.
Any pointers on how to approach this problem would be greatly appreciated.

/r/django
https://redd.it/5l2a2v
Is there a Markdown alternative to sphinx-apidoc for autogenerating documentation from source?

While I appreciate the functionality of sphinx, I really think that Markdown is a better plaintext format than Restructured Text, so I've been writing documentation using [mkdocs](http://www.mkdocs.org/), which works really well for guides etc.

However, when it comes to generating API documentation from docstrings, there don't seem to be many options that support Markdown or straight-to-HTML. One option is [pdoc](http://pdoc.burntsushi.net/pdoc), which works very well but doesn't support structured docstrings in any of Sphinx, Google, or Numpy style.

Does anyone know of a better option for such a purpose?

/r/Python
https://redd.it/5l6r7v
Did Python Earn You Any Passive Income in 2016?

Inspired by this post from [HackerNews](https://news.ycombinator.com/item?id=13150144).

Did you automate, create, or somehow leverage python for any side hustle this year?

/r/Python
https://redd.it/5l7wgc
How to improve UI of manytomany field?

I searched this on Google thinking that it is going to be a common question but to my surprise not a whole lot of info there. Django Admin UI is very good but can we replicate that in our templates? I am open to other ideas also. Thank You in advance.

/r/django
https://redd.it/5l2zfb
Mark Zuckerberg recommending Python

I was reading through this article on "Building Jarvis" by Mark Zuckerberg. Though the title pic is full of non Python code ( I think it is Perl or is it PHP?) that was a let down, this is a overall fantastic work, which he says he has coded in Python, ObjC & PHP.

https://www.facebook.com/notes/mark-zuckerberg/building-jarvis/10154361492931634

In the comments section though I saw this which is very important.

Mark Brady: This is fantastic! In one of your comments, you said, "No regrets. Let's just make sure we teach our children to code!". My son is very interested in coding and asked me for a book for beginners. In order to "future proof" his capabilities (if there are any..?), what language(s) should he focus? What's good for getting his confidence?
Like · Reply · 145 · December 19 at 11:41pm

Mark Zuckerberg: I think Python is a safe bet.
Unlike · Reply · 1,038 · December 20 at 12:18pm

/r/Python
https://redd.it/5l9om5
How to implement a rating system?

I want to implement a rating system on my webapp in which users can rate the service of restaurants.

The problem : How can I ensure that users don't abuse the rating? e. g: giving 5 stars to one of their family members who owns the restaurant.

The backend is developed with Django.

Greetings from Germany


/r/django
https://redd.it/5l97ft
A small Guide to help you install Scikit-Learn and Get Started with Machine Learning on Linux
https://techarena51.com/index.php/getting-started-machine-learning-linux-python-3-scikit-learn/?utm_source=r-python

/r/Python
https://redd.it/5l9gtg
Django points to the wrong version of Postgres

I downgraded Postgres.app from 9.6 to 9.5 by removing the Postgres.app desktop app. I updated the database by doing

(I downloaded Postgres by downloading Postgres.app Desktop app and I installed Django by doing pip install Django)

sudo /usr/libexec/locate.updatedb
And it looks like it is initiating database from the right directory.

/Applications/Postgres.app/Contents/Versions/9.5/bin/initdb
/Applications/Postgres.app/Contents/Versions/9.5/share/doc/postgresql/html/app-initdb.html
/Applications/Postgres.app/Contents/Versions/9.5/share/man/man1/initdb.1

However, when I am trying to do a migration in my Django app, it looks like the path is still point to the 9.6 version of Postgress

Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/Users/me/Desktop/myapp/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/Users/me/Desktop/myapp/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 341, in execute
django.setup()
File "/Users/me/Desktop/myapp/venv/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/me/Desktop/myapp/venv/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/Users/me/Desktop/myapp/venv/lib/python2.7/site-packages/django/apps/config.py", line 199, in import_models
self.models_module = import_module(models_module_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/me/Desktop/myapp/venv/lib/python2.7/site-packages/tenant_schemas/models.py", line 4, in <module>
from tenant_schemas.postgresql_backend.base import _check_schema_name
File "/Users/me/Desktop/myapp/venv/lib/python2.7/site-packages/tenant_schemas/postgresql_backend/base.py", line 14, in <module>
import psycopg2
File "/Users/me/Desktop/myapp/venv/lib/python2.7/site-packages/psycopg2/__init__.py", line 50, in <module>
from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: dlopen(/Users/me/Desktop/myapp/venv/lib/python2.7/site-packages/psycopg2/_psycopg.so, 2): Library not loaded: /Applications/Postgres.app/Contents/Versions/9.6/lib/libpq.5.dylib
Referenced from: /Users/me/Desktop/myapp/venv/lib/python2.7/site-packages/psycopg2/_psycopg.so
Reason: image not found


What I have tried:
1. uninstalled and reinstalled psycopg2
2. updated my database

Does anyone have recommendation as of how to reset path reference?




/r/django
https://redd.it/5kypf9
Would somebody be willing to do a rapid Q+A fire with me/code review with setting up my Flask backend for an iOS app?

Wondering if anyone is willing. I don't feel like just copying and pasting code, it would be much easier if I could talk in a chatroom type setting with somebody looking at my github repo. This is my first time setting up a backend and I think I'm on the right track with getting everything setup with Alamofire and proper routing, but I'm stuck on some nitty gritty stuff.

/r/flask
https://redd.it/5lbbou
Field metadata for name of choices

I've got a problem, I'm hoping someone here could help me.

If I have a field that has choices defined for it and I do

blah = field.choices it returns the tuple such as [('requested', 'Requested'), ('company-approval', 'Ready for Company Approval'), ('client-approval', 'Ready for Client Approval')]

what I'm looking for is what would I access for it to just return to me the variable that tuple is stored in in the models file.

Ex) if you have
status = models.CharField(choices=STATUS_CHOICES)
i'd want it to return to me 'STATUS_CHOICES' instead of the contents of that tuple


Thanks in advance!

/r/django
https://redd.it/5kyw3w