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
Django WordPress competitor?

What is the WordPress framework of the Django world? I want to throw up a site that's blog oriented and I'm contemplating brushing up on PHP 7 or just scrapping that and learning Python to throw up some kind of Django solution. Thanks for the direction.

/r/django
https://redd.it/8b3zk1
How do you implement reset password functionality with Django Rest Framework?

Hi devs,

I'm having a bit of trouble to understand this, without DRF I did it successfully by using Django's default auth views and creating my templates but what about DRF?

Should I create a model that stores a token on the database and them verify if the token is valid for the user? If so, how to best generate this token, what to keep in mind to make the implementation as safe as possible?

Can I use Django's own mechanism which, by what I read, takes into account the last login, the current password (?), and adds some salt? This seems to be a very well thought implementation but can I borrow that mechanism into my RESTful views?

How are you (more experienced) guys doing this?

PS: I'm using only Simple JWT, not using other auth libraries like allauth or social login, don't know if this is relevant to the case.

/r/django
https://redd.it/8b3bur
How to submit Form using Ajax in Django

I need to submit an HTML Form using an Ajax call. I don't know why nothing is happening on clicking the button (Upload Files), I checked the browser console but no error.

Here is the code

index.html
https://dpaste.de/2yO4

views.py
https://dpaste.de/rMQm

Complete code
https://www.dropbox.com/sh/2pq1x6tet7td4jq/AAB-l42AQg1w22RRRG-4AUQna?dl=0

/r/django
https://redd.it/8b5pv5
Heroku Django application error!

Hey guys i have created my first django website! and i want to upload it through Heroku, So i followed everything they said to me and i am still getting application error wheni am trying to do
heruko open
I get an application error and as i am beginner to heruko i am frustrated to get errors! I found that i am getting error here while i do
git push heruko master
I get all things ready but a small error after deploying is done and the error is:

Counting objects: 30, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (30/30), done.
Writing objects: 100% (30/30), 13.62 KiB | 422.00 KiB/s, done.
Total 30 (delta 2), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Python app detected
remote: -----> Installing pip
remote: -----> Installing requirements with pip
remote:
remote: -----> $ python manage.py collectstatic --noinput
remote: 118 static files copied to
'/tmp/build_d2ad5fb0675c6c8305a3ad0fb5
819fe4/static', 131 post-processed.
remote:
remote: -----> Discovering process types
remote: Procfile declares types -> (none)
remote:
remote: -----> Compressing...
remote: Done: 54.3M
remote: -----> Launching...
remote: Released v9
remote: https://kiran-portfolio.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/kiran-portfolio.git
dd0eec5..f9d7b19 master -> master
error: update_ref failed for ref 'refs/remotes/heroku/master': cannot lock ref '
refs/remotes/heroku/master': unable to resolve reference
'refs/remotes/heroku/ma
ster': reference broken

I also think the error is with the Procfile because i don't know what name we should type in the wsgi.py as given below:
web: guincorn whatnameshouldiwrite.wsgi

I found that we should write our app name but i have two apps in my project and i have different name for my heroku website and a different name for my project on my PC so which name should i write there?

The heroku logs looks like:

2018-04-10T08:14:54.924974+00:00 app[api]: Enable Logplex by user smschavan143@g
mail.com
2018-04-10T08:14:54.924974+00:00 app[api]: Release v2 created by user smschavan1
43@gmail.com
2018-04-10T08:14:54.816584+00:00 app[api]: Release v1 created by user smschavan1
43@gmail.com
2018-04-10T08:14:54.816584+00:00 app[api]: Initial release by user smschavan143@
gmail.com
2018-04-10T08:15:27.492135+00:00 heroku[router]: at=info code=H81 desc="Blank ap
p" method=GET path="/" host=kiran-portfolio.herokuapp.com request_id=fc6bbee0-4c
46-4896-b597-07c430591135 fwd="45.117.31.196" dyno= connect= service= status=502
bytes= protocol=https
2018-04-10T08:15:31.386132+00:00 heroku[router]: at=info code=H81 desc="Blank ap
p" method=GET path="/favicon.ico" host=kiran-portfolio.herokuapp.com request_id=
daa19840-978e-46f1-9e69-4c031feecdcb fwd="45.117.31.196" dyno= connect= service=
status=502 bytes= protocol=https
2018-04-10T08:28:39.000000+00:00 app[api]: Build started by user smschavan143@gm
ail.com
2018-04-10T08:28:39.000000+00:00 app[api]: Build failed -- check your build logs

2018-04-10T08:29:48.000000+00:00 app[api]: Build started by user smschavan143@gm
ail.com
2018-04-10T08:29:48.000000+00:00 app[api]: Build failed -- check your build logs

2018-04-10T08:30:26.000000+00:00 app[api]: Build started by user smschavan143@gm
ail.com
2018-04-10T08:30:26.000000+00:00 app[api]: Build failed -- check your build logs

2018-04-10T08:31:52.000000+00:00 app[api]: Build started by user smschavan143@gm
ail.com
2018-04-10T08:31:52.000000+00:00 app[api]: Build failed -- check your build logs

2018-04-10T08:34:55.000000+00:00 app[api]: Build started by user smschavan143@gm
ail.com
2018-04-10T08:34:55.000000+00:00 app[api]: Build failed -- check your build logs

2018-04-10T08:41:23.000000+00:00 app[api]: Build started by user smschavan143@gm
ail.com
2018-04-10T08:41:50.953604+00:00 app[api]: Attach DATABASE (@ref:postgresql-ae
ro
dynamic-33012) by user smschavan143@gmail.com
2018-04-10T08:41:50.953604+00:00 app[api]: Release v3 created by user smschavan1
43@gmail.com
2018-04-10T08:41:51.193509+00:00 app[api]: Deploy 76360db4 by user smschavan143@
gmail.com
2018-04-10T08:41:51.193509+00:00 app[api]: Release v4 created by user smschavan1
43@gmail.com
2018-04-10T08:41:23.000000+00:00 app[api]: Build succeeded
2018-04-10T08:51:00.000000+00:00 app[api]: Build started by user smschavan143@gm
ail.com
2018-04-10T08:51:00.000000+00:00 app[api]: Build failed -- check your build logs

2018-04-10T08:52:35.000000+00:00 app[api]: Build started by user smschavan143@gm
ail.com
2018-04-10T08:53:00.830250+00:00 app[api]: Deploy 3885895d by user smschavan143@
gmail.com
2018-04-10T08:53:00.830250+00:00 app[api]: Release v5 created by user smschavan1
43@gmail.com
2018-04-10T08:52:35.000000+00:00 app[api]: Build succeeded
2018-04-10T08:59:46.000000+00:00 app[api]: Build started by user smschavan143@gm
ail.com
2018-04-10T09:00:10.571878+00:00 app[api]: Release v6 created by user smschavan1
43@gmail.com
2018-04-10T09:00:10.571878+00:00 app[api]: Deploy bbae6e49 by user smschavan143@
gmail.com
2018-04-10T08:59:46.000000+00:00 app[api]: Build succeeded
2018-04-10T09:00:48.993535+00:00 heroku[router]: at=error code=H14 desc="No web
processes running" method=GET path="/" host=kiran-portfolio.herokuapp.com reques
t_id=c3052a19-a59a-4cef-8265-4703bd1557ea fwd="45.117.31.196" dyno= connect= ser
vice= status=503 bytes= protocol=https
2018-04-10T09:00:52.766072+00:00 heroku[router]: at=error code=H14 desc="No web
processes running" method=GET path="/favicon.ico" host=kiran-portfolio.herokuapp
.com request_id=19bda5bc-fcc4-4bb8-9f14-2f4d52a2b0e0 fwd="45.117.31.196" dyno= c
onnect= service= status=503 bytes= protocol=https
2018-04-10T09:08:35.655039+00:00 heroku[router]: at=error code=H14 desc="No web
processes running" method=GET path="/" host=kiran-portfolio.herokuapp.com reques
t_id=5e69f860-dc72-4af3-9040-b1f0ae8af8e4 fwd="45.117.31.196" dyno= connect= ser
vice= status=503 bytes= protocol=https
2018-04-10T09:08:39.157957+00:00 heroku[router]: at=error code=H14 desc="No web
processes running" method=GET path="/favicon.ico" host=kiran-portfolio.herokuapp
.com request_id=2b372932-2ce2-4d45-9cdd-4f59b4422d76 fwd="45.117.31.196" dyno= c
onnect= service= status=503 bytes= protocol=https
2018-04-10T09:09:45.451328+00:00 heroku[router]: at=error code=H14 desc="No web
processes running" method=GET path="/" host=kiran-portfolio.herokuapp.com reques
t_id=d4de5c0a-c590-4b14-adc0-739cbe859feb fwd="45.117.31.196" dyno= connect= ser
vice= status=503 bytes= protocol=https
2018-04-10T09:09:52.145707+00:00 heroku[router]: at=error code=H14 desc="No web
processes running" method=GET path="/favicon.ico" host=kiran-portfolio.herokuapp
.com request_id=1392d710-b0b4-4a77-a01e-735041d98433 fwd="45.117.31.196" dyno= c
onnect= service= status=503 bytes= protocol=https
2018-04-10T09:10:00.000000+00:00 app[api]: Build started by user smschavan143@gm
ail.com
2018-04-10T09:10:26.434601+00:00 app[api]: Deploy 9d697adf by user smschavan143@
gmail.com
2018-04-10T09:10:26.434601+00:00 app[api]: Release v7 created by user smschavan1
43@gmail.com
2018-04-10T09:10:00.000000+00:00 app[api]: Build succeeded
2018-04-10T09:10:47.723358+00:00 heroku[router]: at=error code=H14 desc="No web
processes running" method=GET path="/" host=kiran-portfolio.herokuapp.com reques
t_id=b0f6be6e-393e-4416-b4d3-edb759292fa6 fwd="45.117.31.196" dyno= connect= ser
vice= status=503 bytes= protocol=https
2018-04-10T09:10:51.163961+00:00 heroku[router]: at=error code=H14 desc="No web
processes running" method=GET path="/favicon.ico" host=kiran-portfolio.herokuapp
.com request_id=cf906ebf-a5b9-42d3-98d7-0df7229e3d1e fwd="45.117.31.196" dyno= c
onnect= service= status=503 bytes= protocol=https
2018-04-10T09:10:56.992860+00:00 heroku[router]: at=error code=H14 desc="No web
processes running" method=GET path="/" host=kiran-portfolio.herokuapp.com reques
t_id=ce6d8b95-7508-
4e1e-8610-684369b3e0cd fwd="45.117.31.196" dyno= connect= ser
vice= status=503 bytes= protocol=https
2018-04-10T09:10:58.488848+00:00 heroku[router]: at=error code=H14 desc="No web
processes running" method=GET path="/favicon.ico" host=kiran-portfolio.herokuapp
.com request_id=9e1727a7-806d-490d-94ee-8a779beb21a8 fwd="45.117.31.196" dyno= c
onnect= service= status=503 bytes= protocol=https


Thanks,

/r/django
https://redd.it/8b6bvh
What are some simple django-based blog projects which developers starting in webdev can use?

I am looking to start a django-based blog and would like to see if people have any recommendations for "ready-made" projects. Something like this as an example: https://github.com/miguelgfierro/sciblog.

My objective is to get the blog up and running as soon as possible and customize it with time. My theoretical webdev knowledge is good although I have zero practical experience and I want to take this opportunity to learn.

What are some simple django-based blog projects which developers new to webdev can start with?

/r/django
https://redd.it/8b7jt8
Anyone use Okta? Is it as easy as Flask-Login?

I'm just starting out with Flask, have found using Flask-Login really easy and pretty cool. But I'm worried about data protection, and thought using Okta might reduce liability. Anyone doing the same? Can it integrate with Flask-Login? The workflow for Okta looks pretty heavy - any opinions?

/r/flask
https://redd.it/8b7ik6
Best library for creating charts

Hi, I'm doing the final touches of a website (a 3-buildings warehouse) and I tought it would be cool to generate charts for a quick visualization of some of the information. I did a bit of googling to search what's the best library for Django and I found a lot of them, mainly Highcharts, Dash/Plotly, D3JS, Charts.js and many more.

What's the best (and easy to implement) library to create charts in a Django website you've ever used?

/r/django
https://redd.it/8b8nxq
What's everyone working on this week?

Tell /r/python what you're working on this week! You can be bragging, grousing, sharing your passion, or explaining your pain. Talk about your current project or your pet project; whatever you want to share.


/r/Python
https://redd.it/8b7uc8
Heroku Procfile automatically turns to .txt file

Hey guys i have been changing the Procfile name on Heroku with no extension through the cmd but every time i do a "git push heroku master" automatically the Procfile turns to Procfile.txt! What could have caused the problem?

/r/djangolearning
https://redd.it/8b7nz7
How do I configure Jupyter Notebooks to open in a browser?

When I open a Jupyter Notebook, I want it to open in a new tab of an existing Firefox window. In my ~/.jupyter/jupyter_notebook_config.py file, I try

c.NotebookApp.browser = '/usr/bin/firefox'

With this, I get a popup error from Firefox to the effect that "Firefox is already running", which isn't unexpected. You need to use command line flags to affect an already existing instance of Firefox, so I try

c.NotebookApp.browser = '/usr/bin/firefox -P default -new-tab'

When I do this, the terminal output from Jupyter gives the error

FileNotFoundError: [Errno 2] No such file or directory: '/usr/bin/firefox -P default -new-tab': '/usr/bin/firefox -P default -new-tab'

How do I tell Jupyter to open Firefox with command-line options?

/r/JupyterNotebooks
https://redd.it/8b8mtq
Best way to handle file uploads?

Im trying to setup image uploads in a local Flask app with Flask-uploads. I think Im almost there but not able to finish it.

This is my form (using flask_wtf):

class AddBookForm(FlaskForm):
title = StringField('Title', validators=[DataRequired()])
author = StringField('Author', validators=[DataRequired()])
category = StringField('Category', validators=[DataRequired()])
image = FileField('Image', validators=[FileRequired()])

this is my template:

<form action="/upload" method="post" enctype="multipart/form-data" >
<span class="btn btn-default btn-file">
Browse <input type="file" name="image">
</span>

<input type="submit" value="Upload your image" class="btn btn-primary">
</form>

and then finally these are the important bits from views.py:

from flask.ext.uploads import UploadSet, configure_uploads, IMAGES, UploadNotAllowed

photos = UploadSet('photos', IMAGES, default_dest=lambda app: os.path.basename('uploads'))
configure_uploads(app, (photos,))

@app.route('/upload', methods=['GET', 'POST'])
def upload():
if request.method == 'POST' and 'image' in request.files:
filename = photos.save(request.files['image'])
rec = Photo(filename=filename, user=g.user.id)
rec.store()
flash("Photo saved.")
return redirect(url_for('show', id=rec.id))
return render_template('upload.html')

@app.route('/photo/<id>')
def show(id):
photo = Photo.load(id)
if photo is None:
abort(404)
url = photos.url(photo.filename)
return render_template('show.html', url=url, photo=photo)

As it stands right now when I go to /upload and fill in the form with an image the file does actually get uploaded to my 'uploads' directory in my app but this error is shown in the console:

File "/Users/david/Documents/projects/flask_store/storeapp/views.py", line 236, in upload
rec = Photo(filename=filename, user=g.user.id)
NameError: name 'Photo' is not defined

there is no object named 'Photo' but if I changed the fields in my from from 'image' to 'photo' then try and upload an image again I get no errors that time but the image doesn't get uploaded to the local 'uploads' directory.

What am I missing here?

thanks


/r/flask
https://redd.it/8b8l7l
Flask and nodejs

Ok i have been reading online and i see that a lot of people and alot of companies are switching to nodejs im not a professional web developer but i like to build for personal use and for learning.

Is flask or django dying and what are the benefits of nodejs over flask (which is what i use)

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