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
Help fixing flask endpoints

Hello everyone, I had a friend code review a simple to do app that I made with flask. He said that my end points were atypical of a RESTful API and I didn't understand exactly what he meant. He specified by saying that each endpoint should return the specific object that they are manipulating. Could anyone give me some more clarification on this? He doesn't work with python and works with ruby so I had some specific syntax questions. Here's my views.py

https://github.com/snovosel/RESTful_to_do/blob/master/python_todo/views.py

Each view function returns all of the information needed for the front end each time. So i'm not exactly sure what the problem with that is. Hopefully someone can shed some light on this.

Thank you!

/r/flask
https://redd.it/6bn9o1
Good Tutorials on modifying/extending Django Admin site?

Could you folks suggest some good tutorials on modifying/extending Django Admin site?
It would be awesome if they touch on using ajax inside Django Admin. Thank you!

/r/django
https://redd.it/6bknyx
Group By and Sum Query

Can anyone help me construct a query that looks like https://dpaste.de/fxAf in a view? I've attempted https://dpaste.de/cCar but get an AttributeError.

I'm using django-graphos to pass this into a chart.

/r/django
https://redd.it/6botq2
PyCon Sale of Python Books / Online Courses

Educative and I are doing a sale of Python books and courses. I am putting all my books and courses on sale at 50% off for PyCon. Educative does online interactive courses and when you purchase a course, you get **lifetime access**.

Let's start with the Educative courses. To get them for 50% off, you just need to use the following coupons:

* For [Python 101](https://www.educative.io/collection/5663684521099264/5707702298738688) – **au-pycon-reddit-101**
* For [Python 201: Intermediate Python](https://www.educative.io/collection/5663684521099264/5693417237512192) – **au-pycon-reddit-201**

Educative is also putting their [Python 3: An interactive deep dive](https://www.educative.io/collection/10370001/5705097937944576) course on sale for 50% off if you use this coupon: **au-pycon-reddit-deepdive**

Finally they also gave me a coupon for one of other courses: [Coderust 2.0: Faster Coding Interview Preparation using Interactive Visualizations](https://www.educative.io/collection/5642554087309312/5679846214598656) - **au-pycon-reddit-coderust** (Note that this coupon is only 17% off though.

For the eBook (PDF, mobi, epub) versions of my books, I am also doing a 50% off sale on Leanpub:

* [Python 101](http://leanpub.com/python_101/) is free or pay what you want
* [Python 201: Intermediate Python](http://leanpub.com/python201/c/50percent)
* [wxPython Cookbook](http://leanpub.com/wxpythoncookbook/c/50percent)


/r/Python
https://redd.it/6bomkd
Programmatically create a user with python-social-auth

I'm using python-social-auth so that users can log in with their google accounts. However, rather than allowing users to register, I want to programmatically create users given an email associated with their google account. How can I do this?

Thanks!

/r/django
https://redd.it/6btkfo
django not logging errors to file when running on nginx

I'm running a django app with uwsgi and nginx. I'm trying to have to django log some 500 errors so I can debug an issue but for some reason it is not writing to the file I've specified when I access my app at its domain. The logging works fine when I manually test the app using uwsgi.

here's my nginx.conf

#nginx.conf
upstream django {
# connect to this socket
server unix:/tmp/uwsgi.sock; # for a file socket
#server 127.0.0.1:8001; # for a web port socket
}

server {

listen 80 default_server;
server_name mysite.org
return 301 https://$server_name$request_uri;

}

server {
# the port your site will be served on
#listen 80 default_server;
#listen 8000;

listen 443 ssl;

root /opt/apps/site-env/trust_site;

# the domain name it will serve for
server_name mysite.org


#Max upload size
client_max_body_size 75M; # adjust to taste

# Django media
location /media {
alias /opt/apps/site-env/site/media; # your
Django project's media files
}

location /static {
alias /opt/apps/site-env/site/static; # your Django
project's static files
}

location / {
uwsgi_pass django;

include /etc/nginx/uwsgi_params;

proxy_pass_header X-CSRFToken;
#proxy_set_header X-Forwarded-Proto https;
#proxy_set_header HOST $host;

}


}

help anyone?

/r/django
https://redd.it/6btiwt
How to protect urls

I want to protect my media files, and have done this like so, in url.py:

from django.conf.urls import patterns, include, url
from django.contrib.auth.decorators import login_required
from django.views.static import serve
from django.conf import settings


@login_required
def protected_serve(request, path, document_root=None, show_indexes=False):
return serve(request, path, document_root, show_indexes)

urlpatterns = patterns('',
url(r'^%s(?P<path>.*)$' % settings.MEDIA_URL[1:], protected_serve, {'document_root': settings.MEDIA_ROOT}),
)

and this works, so i can only acces the media file if i am logged in. But i want to be able to grant acces to each file, so not only do you need to login you also need to have acces right to this file, so i made this model.


from django.contrib.auth.models import User
from upload import models as upload_models

class UserVideo(models.Model):
user = models.ForeignKey(User,related_name='_myfiles')

file = models.ForeignKey(upload_models.Document)

def __str__(self):
return u'%s - %s' % (self.user, self.file)

its a list of users and what video each user can see, so i can do something like:

myfiles = request.user._myfiles.all()

and get all the files.

how do i protect the url, so instead of checking if i am logged in, it also check if i have acces to it in this model? is this possible to do in the url.py ?

/r/djangolearning
https://redd.it/6bvae0
Using Flask for big applications as E-commerce

I've been using Flask for the last couple of years, but I just developed small applications for the companies that worked for.
I'm willing to develop a big e-commerce web system with Flask, but I don't know if it's gonna last. Based on my researches, Flask was never used on a application like that.
Well, shoud I try?

Thanks!

/r/flask
https://redd.it/6bwn2k