manage.py migrate: [migration_name] just needs the first few characters
EDIT: looking at the comments I think I should add some context. Say you did a migration and want to undo the database changes (so it doesn't screw up future migrations), you can run `manage.py migrate [app_label] [migration_name]` where migration_name is the filename of the previous migration you wish to revert to. What's not clear in the docs is that you can actually use just the first few characters of the filename, so long as there are no clashes.
---
I feel silly for not trying this before, but when doing `manage.py migrate app_label migration_name` you can actually just use the first few characters of a migration for `migration_name` e.g. if your migration file is 0018_auto_20170802_1822.py, you can just use `manage.py migrate app_label *0018*`.
This works because the function to get the migration uses `startswith()`: https://github.com/django/django/blob/master/django/db/migrations/loader.py#L134
Hope this helps if you're trying to undo a previous migration!
/r/django
https://redd.it/8eal1n
EDIT: looking at the comments I think I should add some context. Say you did a migration and want to undo the database changes (so it doesn't screw up future migrations), you can run `manage.py migrate [app_label] [migration_name]` where migration_name is the filename of the previous migration you wish to revert to. What's not clear in the docs is that you can actually use just the first few characters of the filename, so long as there are no clashes.
---
I feel silly for not trying this before, but when doing `manage.py migrate app_label migration_name` you can actually just use the first few characters of a migration for `migration_name` e.g. if your migration file is 0018_auto_20170802_1822.py, you can just use `manage.py migrate app_label *0018*`.
This works because the function to get the migration uses `startswith()`: https://github.com/django/django/blob/master/django/db/migrations/loader.py#L134
Hope this helps if you're trying to undo a previous migration!
/r/django
https://redd.it/8eal1n
GitHub
django/django
django - The Web framework for perfectionists with deadlines.
DjBrut: bruteforce protection for Django with Redis backend. Customizable, extendable, fast.
https://github.com/orsinium/django-bruteforce-protection
/r/django
https://redd.it/8ed2og
https://github.com/orsinium/django-bruteforce-protection
/r/django
https://redd.it/8ed2og
GitHub
orsinium/django-bruteforce-protection
Bruteforce protection for Django projects based on Redis. Simple, powerful, extendable. - orsinium/django-bruteforce-protection
PyGotham 2018 Call for Proposals
https://www.papercall.io/pygotham-2018
/r/django
https://redd.it/8ec6mc
https://www.papercall.io/pygotham-2018
/r/django
https://redd.it/8ec6mc
www.papercall.io
PaperCall.io - PyGotham 2018
PyGotham 2018 is taking place from October 5-6 at the Hotel Pennsylvania in New York City. It will feature three tracks of talks on Friday, October 5th and Saturday, October 6th.
## Background
PyGotham is a New York City based, eclectic, Py-centric conference…
## Background
PyGotham is a New York City based, eclectic, Py-centric conference…
[AF] Request.referrer gives BuildError when redirecting to the same endpoint.
Hi, so I have a website that enables voting, much like on reddit, and I've tried to make it so that whenever the user votes he is instantly redirected back to wherever he initially viewed a post. So say I upvoted a post when viewing it, I expect to be redirected back to the post, not the front page.
Here is the code I used, taken from a snippet:
def redirect_url():
return request.args.get('next') or \
request.referrer or \
url_for('index')
And here is where it is implemented:
@app.route('/vote/<post_id>', methods=['POST'])
def vote(post_id):
post = Post.query.filter_by(id=post_id).first()
if post != None:
if post.upvotes == None:
post.make_vote_int()
if "upvote" in request.form:
post.upvotes = post.upvotes + 1
post.get_score()
db.session.commit()
if "downvote" in request.form:
post.downvotes = post.downvotes + 1
post.get_score()
db.session.commit()
return redirect(url_for(redirect_url()))
Using this I receive this error:
werkzeug.routing.BuildError: Could not build url for endpoint 'http://localhost:5000/
when voting wherever.
What am I doing wrong and how can I fix it?
Here is the github link, however I haven't yet pushed this code yet.
https://github.com/ModoUnreal/dopenet
/r/flask
https://redd.it/8efkzl
Hi, so I have a website that enables voting, much like on reddit, and I've tried to make it so that whenever the user votes he is instantly redirected back to wherever he initially viewed a post. So say I upvoted a post when viewing it, I expect to be redirected back to the post, not the front page.
Here is the code I used, taken from a snippet:
def redirect_url():
return request.args.get('next') or \
request.referrer or \
url_for('index')
And here is where it is implemented:
@app.route('/vote/<post_id>', methods=['POST'])
def vote(post_id):
post = Post.query.filter_by(id=post_id).first()
if post != None:
if post.upvotes == None:
post.make_vote_int()
if "upvote" in request.form:
post.upvotes = post.upvotes + 1
post.get_score()
db.session.commit()
if "downvote" in request.form:
post.downvotes = post.downvotes + 1
post.get_score()
db.session.commit()
return redirect(url_for(redirect_url()))
Using this I receive this error:
werkzeug.routing.BuildError: Could not build url for endpoint 'http://localhost:5000/
when voting wherever.
What am I doing wrong and how can I fix it?
Here is the github link, however I haven't yet pushed this code yet.
https://github.com/ModoUnreal/dopenet
/r/flask
https://redd.it/8efkzl
GitHub
ModoUnreal/dopenet
dopenet - The ideal template to make websites in 2018!!!! (I'm kidding of course)
AI based keyboard for disabled people. (In python using tensorflow)
https://youtu.be/YLNDTA2cE1Q
/r/Python
https://redd.it/8ejf2m
https://youtu.be/YLNDTA2cE1Q
/r/Python
https://redd.it/8ejf2m
YouTube
AI based handwriting keyboard
this is a keyboard I created to help disabled people to use computers using a neural network.
I shipped my first real Django project, an easy way to make your own job board
Hey there y'all! I recently built [Seeker](https://seeker.company), an easy way for people to make their own paid job boards. I built this using Django in the back-end with Django Rest Framework and Vue.js on the front-end. Postgres is the database (hosted in Google Cloud) and it's deployed to Heroku.
/r/django
https://redd.it/8egd1h
Hey there y'all! I recently built [Seeker](https://seeker.company), an easy way for people to make their own paid job boards. I built this using Django in the back-end with Django Rest Framework and Vue.js on the front-end. Postgres is the database (hosted in Google Cloud) and it's deployed to Heroku.
/r/django
https://redd.it/8egd1h
seeker.company
Seeker is the easiest way to host your own job board!
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/8ekob5
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/8ekob5
reddit
What's everyone working on this week? • r/Python
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...
Integrating S3 (static + media vs media)
This isn't specific to Django or S3 but conceptually it should be the same. I'm using Flask \+ Digital Ocean Spaces \(API is compatible with S3\) but I figured that this subreddit would have a larger reach, especially since I've found way more S3\+Django tutorials than Spaces\+Flask/S3\+Flask. I'm just looking for a conceptual understanding on how I should integrate S3.
My application is running on DO behind Nginx. Nginx is configured to serve my static files. I wanted to move my user\-uploaded media files onto S3.
I've noticed that most tutorials explain how to serve your static assets \(JS/CSS\) and media files from S3 using something like django\-storages \(flask\-s3 is the flask counterpart\) \+ boto3.
1. Would it be unidiomatic to configure S3 to serve only media files? I just wanted to make sure because I've just deployed my site a week ago and this is all new to me. This makes sense to me but I didn't want to go against the grain for no reason.
2. The only advantage for serving static assets \(JS/CSS\) from S3 is to take advantage of a CDN \(e.g. Cloudfront\) so that your reverse proxy \(e.g. Nginx\) can focus only on load balancing, right? I always had the idea that S3 was primarily for media files to save space on your VM. I never thought people used it for static assets too.
EDIT:
**TLDR: Static assets: Nginx or S3?**
/r/django
https://redd.it/8emhrq
This isn't specific to Django or S3 but conceptually it should be the same. I'm using Flask \+ Digital Ocean Spaces \(API is compatible with S3\) but I figured that this subreddit would have a larger reach, especially since I've found way more S3\+Django tutorials than Spaces\+Flask/S3\+Flask. I'm just looking for a conceptual understanding on how I should integrate S3.
My application is running on DO behind Nginx. Nginx is configured to serve my static files. I wanted to move my user\-uploaded media files onto S3.
I've noticed that most tutorials explain how to serve your static assets \(JS/CSS\) and media files from S3 using something like django\-storages \(flask\-s3 is the flask counterpart\) \+ boto3.
1. Would it be unidiomatic to configure S3 to serve only media files? I just wanted to make sure because I've just deployed my site a week ago and this is all new to me. This makes sense to me but I didn't want to go against the grain for no reason.
2. The only advantage for serving static assets \(JS/CSS\) from S3 is to take advantage of a CDN \(e.g. Cloudfront\) so that your reverse proxy \(e.g. Nginx\) can focus only on load balancing, right? I always had the idea that S3 was primarily for media files to save space on your VM. I never thought people used it for static assets too.
EDIT:
**TLDR: Static assets: Nginx or S3?**
/r/django
https://redd.it/8emhrq
reddit
Integrating S3 (static + media vs media) • r/django
This isn't specific to Django or S3 but conceptually it should be the same. I'm using Flask \+ Digital Ocean Spaces \(API is compatible with S3\)...
Google PageSpeed is saying my server response time is too long (340ms). How can I improve it ?
I'm using PythonAnywhere for hosting.
I've installed django-debug-toolbar but don't really know how to use it. It's reporting 76 queries in 42ms for SQL, which doesn't seem to be causing my issue.
This is my PageSpeed link : https://developers.google.com/speed/pagespeed/insights/?url=https%3A%2F%2Fwww.tavolia.fr%2F
/r/djangolearning
https://redd.it/8emq9z
I'm using PythonAnywhere for hosting.
I've installed django-debug-toolbar but don't really know how to use it. It's reporting 76 queries in 42ms for SQL, which doesn't seem to be causing my issue.
This is my PageSpeed link : https://developers.google.com/speed/pagespeed/insights/?url=https%3A%2F%2Fwww.tavolia.fr%2F
/r/djangolearning
https://redd.it/8emq9z
Pipenv: A Guide to the New Python Packaging Tool
https://realpython.com/pipenv-guide/
/r/Python
https://redd.it/8elkqe
https://realpython.com/pipenv-guide/
/r/Python
https://redd.it/8elkqe
Realpython
Pipenv: A Guide to the Python Packaging Tool – Real Python
Pipenv is a packaging tool for Python that solves some common problems associated with the typical workflow using pip, virtualenv, and the good old requirements.txt. This guide goes over what problems Pipenv solves and how to manage your Python dependencies…
What is up with this return redirect line?
main is just my homepage and / is the url. For some reason, I can't get signUp to return back to the homepage after finishing.
return redirect(function) goes return redirect(main) (since thats the name of home being rendered.
I can also confirm 'here' and 'Registered' get printed. Also, in my terminal, i get
127.0.0.1 - - [23/Apr/2018 23:13:51] "GET / HTTP/1.1" 200 -
Which means it SHOULD be going to home, because I get the same line when I just click the home link on the page. It redirects too. What happens with the flask is it just stays on the login page. Nothing else, no errors thrown. Just sits there.
@app.route("/")
def main():
return render_template('Senty.html')
@app.route('/signUp',methods=['POST','GET'])
def signUp():
# still need to create signup class and transfer below code to new file
conn = mysql.connect()
cur = conn.cursor()
try:
_name = request.form['inputName']
_email = request.form['inputEmail']
_password = request.form['inputPassword']
# validate the received values
if _name and _email and _password:
cur.callproc('sp_createUser',(_name,_email,_password,))
print ("Registered")
data = cur.fetchall()
conn.commit()
json.dumps({'message':'User created successfully !'})
print('here')
return redirect(url_for('main'))
#else:
#return json.dumps({'html':'<span>Enter the required fields</span>'})
#except Exception as e:
#return json.dumps({'error':str(e)})
finally:
cur.close()
conn.close()
@app.route('/showSignIn')
def showSignIn():
return(render_template('login.html'))
I'm not sure where to go. I feel like I've tried everything.
/r/flask
https://redd.it/8ei5hq
main is just my homepage and / is the url. For some reason, I can't get signUp to return back to the homepage after finishing.
return redirect(function) goes return redirect(main) (since thats the name of home being rendered.
I can also confirm 'here' and 'Registered' get printed. Also, in my terminal, i get
127.0.0.1 - - [23/Apr/2018 23:13:51] "GET / HTTP/1.1" 200 -
Which means it SHOULD be going to home, because I get the same line when I just click the home link on the page. It redirects too. What happens with the flask is it just stays on the login page. Nothing else, no errors thrown. Just sits there.
@app.route("/")
def main():
return render_template('Senty.html')
@app.route('/signUp',methods=['POST','GET'])
def signUp():
# still need to create signup class and transfer below code to new file
conn = mysql.connect()
cur = conn.cursor()
try:
_name = request.form['inputName']
_email = request.form['inputEmail']
_password = request.form['inputPassword']
# validate the received values
if _name and _email and _password:
cur.callproc('sp_createUser',(_name,_email,_password,))
print ("Registered")
data = cur.fetchall()
conn.commit()
json.dumps({'message':'User created successfully !'})
print('here')
return redirect(url_for('main'))
#else:
#return json.dumps({'html':'<span>Enter the required fields</span>'})
#except Exception as e:
#return json.dumps({'error':str(e)})
finally:
cur.close()
conn.close()
@app.route('/showSignIn')
def showSignIn():
return(render_template('login.html'))
I'm not sure where to go. I feel like I've tried everything.
/r/flask
https://redd.it/8ei5hq
reddit
What is up with this return redirect line? • r/flask
main is just my homepage and / is the url. For some reason, I can't get signUp to return back to the homepage after finishing. return...
Looking for guidance on creating models
Hi, I have a python script for teachers with some dummy data but now I would like to serve it on the web for others to use.
I ultimately want to create a table where the user can create their own schedule with these input fields:
* the table's name should be the teacher's first and last name
* the x\-axis are the days of the week \(Mon \- Fri\)
* the y\-axis are the periods from \(1\-8\)
I'm having immense trouble figuring out how to create the models in flask because some of data are related to each other so I feel like I should be using ForeignKeys and ManyToMany.
Many thanks to everyone for their guidance.
/r/flask
https://redd.it/8eppzj
Hi, I have a python script for teachers with some dummy data but now I would like to serve it on the web for others to use.
I ultimately want to create a table where the user can create their own schedule with these input fields:
* the table's name should be the teacher's first and last name
* the x\-axis are the days of the week \(Mon \- Fri\)
* the y\-axis are the periods from \(1\-8\)
I'm having immense trouble figuring out how to create the models in flask because some of data are related to each other so I feel like I should be using ForeignKeys and ManyToMany.
Many thanks to everyone for their guidance.
/r/flask
https://redd.it/8eppzj
reddit
r/flask - Looking for guidance on creating models
1 votes and 0 so far on reddit
Using Django Rest Framework, how can I give a serializer field a name that is not a valid Python variable name?
I'm trying to serialize the following type of inputs:
{
"1": [],
"2": [],
"3": [],
"4": [],
"5": [],
"6": [],
"7": [],
"8": [],
"9": [],
"10": []
}
But 1,2,... 10 are not valid Python variable names. Ideally I would have
from rest_framework import serializers
class MySerializer(serializers.Serializer):
1 = serializers.ListField(child=serializers.CharField)
2 = serializers.ListField(child=serializers.CharField)
3 = serializers.ListField(child=serializers.CharField)
4 = serializers.ListField(child=serializers.CharField)
5 = serializers.ListField(child=serializers.CharField)
6 = serializers.ListField(child=serializers.CharField)
7 = serializers.ListField(child=serializers.CharField)
8 = serializers.ListField(child=serializers.CharField)
9 = serializers.ListField(child=serializers.CharField)
10 = serializers.ListField(child=serializers.CharField)
I appreciate any help you can offer!
/r/django
https://redd.it/8enwrd
I'm trying to serialize the following type of inputs:
{
"1": [],
"2": [],
"3": [],
"4": [],
"5": [],
"6": [],
"7": [],
"8": [],
"9": [],
"10": []
}
But 1,2,... 10 are not valid Python variable names. Ideally I would have
from rest_framework import serializers
class MySerializer(serializers.Serializer):
1 = serializers.ListField(child=serializers.CharField)
2 = serializers.ListField(child=serializers.CharField)
3 = serializers.ListField(child=serializers.CharField)
4 = serializers.ListField(child=serializers.CharField)
5 = serializers.ListField(child=serializers.CharField)
6 = serializers.ListField(child=serializers.CharField)
7 = serializers.ListField(child=serializers.CharField)
8 = serializers.ListField(child=serializers.CharField)
9 = serializers.ListField(child=serializers.CharField)
10 = serializers.ListField(child=serializers.CharField)
I appreciate any help you can offer!
/r/django
https://redd.it/8enwrd
reddit
r/django - Using Django Rest Framework, how can I give a serializer field a name that is not a valid Python variable name?
3 votes and 9 so far on reddit
PyTorch 0.4.0 released (new NumPy-like API, Windows support, Tensor-Variable merge...)
https://www.reddit.com/r/MachineLearning/comments/8eo154/n_pytorch_v04_windows_support_zerodimensional/
/r/Python
https://redd.it/8eqgad
https://www.reddit.com/r/MachineLearning/comments/8eo154/n_pytorch_v04_windows_support_zerodimensional/
/r/Python
https://redd.it/8eqgad
reddit
r/MachineLearning - [N] PyTorch v0.4: Windows support, zero-dimensional Tensors, Tensor-Variable merge, CuDNN 7.1 and more
246 votes and 77 comments so far on Reddit
Open <p> tags created by django
Has anyone experienced a situation where django has created open \<p\> tags.
I'm passing in the following template tag and it's putting a \<p\> tag in front of the data, but no \</p\> at the end.
{{ article.body|linebreaks|truncatechars:110 }}
/r/django
https://redd.it/8eqfw9
Has anyone experienced a situation where django has created open \<p\> tags.
I'm passing in the following template tag and it's putting a \<p\> tag in front of the data, but no \</p\> at the end.
{{ article.body|linebreaks|truncatechars:110 }}
/r/django
https://redd.it/8eqfw9
reddit
r/django - Open tags created by django
4 votes and 8 so far on reddit