Render? Redirect? When validating form...
Hello, so I'm few week in with Flask, it's real fun, I enjoy it quite a bit. But there are still things I don't understand.
Now I'm fighting with this:
I've got a page `issue_status.html` which contains 2 tables with data acquired from a database. This is a route to which I link my links.
@app.route('/issue_status/')
def issue_status():
cur, db = get_db(cursor=True)
issues = cur.execute("SELECT * FROM issues").fetchall()
resolved, unresolved = [], []
for row in issues:
issue = row[1]
found = cur.execute("SELECT * FROM resolved_issues WHERE issue = ?", [issue]).fetchall()
if len(found) > 0:
resolved.append(row)
else:
unresolved.append(row)
all_issues = {'resolved': resolved, 'unresolved': unresolved}
today = datetime.datetime.today().strftime('%Y-%m-%d')
return render_template('issue_status.html', all_issues=all_issues, today=today)
The page contains a form too for adding new issues. It's in the same `issue_status.html` page. When user clicks on `submit`, it would go to this function:
@app.route('/add_issue/', methods=['GET', 'POST'])
def add_issue():
if not session.get('logged_in'):
abort(401)
cur, db = get_db(cursor=True)
issue = request.form.get('issue')
version = ""
date_resolved = ""
existing = cur.execute("SELECT * FROM issues WHERE issue = ?", [issue]).fetchall()
if len(existing) > 0:
flash("This issue already exists...", 'danger')
return redirect(url_for('issue_status'))
....
....
....
flash('New issue was successfully added into database.', 'success')
return redirect(url_for('issue_status'))
**The problem:** I wanted to add to this function **form validation** but don't know how/what to return if the validation fails.
Because when I render the page, I'm missing the data parsed to `issue_status.html` from `issue_status` function. And when I tried to redirect to `issue_status`, that failed somehow too.
I would like to somehow only show under each field (Issue number, username, Description) a form invalid error without refreshing the page. How to do this elegantly?
If you want to see details what I have till now, the WebApp is at [github.com](https://github.com/SonGokussj4/beta-issues)
Any help would be appreciated.
[Screenshot](http://i.imgur.com/zKXV17W.jpg) for visual aid.
/r/flask
https://redd.it/6cidqh
Hello, so I'm few week in with Flask, it's real fun, I enjoy it quite a bit. But there are still things I don't understand.
Now I'm fighting with this:
I've got a page `issue_status.html` which contains 2 tables with data acquired from a database. This is a route to which I link my links.
@app.route('/issue_status/')
def issue_status():
cur, db = get_db(cursor=True)
issues = cur.execute("SELECT * FROM issues").fetchall()
resolved, unresolved = [], []
for row in issues:
issue = row[1]
found = cur.execute("SELECT * FROM resolved_issues WHERE issue = ?", [issue]).fetchall()
if len(found) > 0:
resolved.append(row)
else:
unresolved.append(row)
all_issues = {'resolved': resolved, 'unresolved': unresolved}
today = datetime.datetime.today().strftime('%Y-%m-%d')
return render_template('issue_status.html', all_issues=all_issues, today=today)
The page contains a form too for adding new issues. It's in the same `issue_status.html` page. When user clicks on `submit`, it would go to this function:
@app.route('/add_issue/', methods=['GET', 'POST'])
def add_issue():
if not session.get('logged_in'):
abort(401)
cur, db = get_db(cursor=True)
issue = request.form.get('issue')
version = ""
date_resolved = ""
existing = cur.execute("SELECT * FROM issues WHERE issue = ?", [issue]).fetchall()
if len(existing) > 0:
flash("This issue already exists...", 'danger')
return redirect(url_for('issue_status'))
....
....
....
flash('New issue was successfully added into database.', 'success')
return redirect(url_for('issue_status'))
**The problem:** I wanted to add to this function **form validation** but don't know how/what to return if the validation fails.
Because when I render the page, I'm missing the data parsed to `issue_status.html` from `issue_status` function. And when I tried to redirect to `issue_status`, that failed somehow too.
I would like to somehow only show under each field (Issue number, username, Description) a form invalid error without refreshing the page. How to do this elegantly?
If you want to see details what I have till now, the WebApp is at [github.com](https://github.com/SonGokussj4/beta-issues)
Any help would be appreciated.
[Screenshot](http://i.imgur.com/zKXV17W.jpg) for visual aid.
/r/flask
https://redd.it/6cidqh
GitHub
SonGokussj4/beta-issues
beta-issues - My first flask app
tinynumpy - a lightweight, pure Python, numpy compliant ndarray class
https://github.com/wadetb/tinynumpy
/r/Python
https://redd.it/6chub7
https://github.com/wadetb/tinynumpy
/r/Python
https://redd.it/6chub7
GitHub
GitHub - wadetb/tinynumpy: A lightweight, pure Python, numpy compliant ndarray class.
A lightweight, pure Python, numpy compliant ndarray class. - GitHub - wadetb/tinynumpy: A lightweight, pure Python, numpy compliant ndarray class.
Just installed django, but get ModuleNotFoundError when I run "django-admin --version" (traceback indluded)
Traceback (most recent call last):
File "C:\Users\X\AppData\Local\Programs\Python\Python36-32\Scripts\django-admin-script.py", line 11, in <module>
load_entry_point('django==1.11.1', 'console_scripts', 'django-admin')()
File "c:\users\x\appdata\local\programs\python\python36-32\lib\site-packages\pkg_resources\__init__.py", line 560, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "c:\users\x\appdata\local\programs\python\python36-32\lib\site-packages\pkg_resources\__init__.py", line 2648, in load_entry_point
return ep.load()
File "c:\users\x\appdata\local\programs\python\python36-32\lib\site-packages\pkg_resources\__init__.py", line 2302, in load
return self.resolve()
File "c:\users\x\appdata\local\programs\python\python36-32\lib\site-packages\pkg_resources\__init__.py", line 2308, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "c:\users\x\appdata\local\programs\python\python36-32\lib\site-packages\django\__init__.py", line 3, in <module>
from django.utils.version import get_version
ModuleNotFoundError: No module named 'django.utils'
/r/django
https://redd.it/6chwky
Traceback (most recent call last):
File "C:\Users\X\AppData\Local\Programs\Python\Python36-32\Scripts\django-admin-script.py", line 11, in <module>
load_entry_point('django==1.11.1', 'console_scripts', 'django-admin')()
File "c:\users\x\appdata\local\programs\python\python36-32\lib\site-packages\pkg_resources\__init__.py", line 560, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "c:\users\x\appdata\local\programs\python\python36-32\lib\site-packages\pkg_resources\__init__.py", line 2648, in load_entry_point
return ep.load()
File "c:\users\x\appdata\local\programs\python\python36-32\lib\site-packages\pkg_resources\__init__.py", line 2302, in load
return self.resolve()
File "c:\users\x\appdata\local\programs\python\python36-32\lib\site-packages\pkg_resources\__init__.py", line 2308, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "c:\users\x\appdata\local\programs\python\python36-32\lib\site-packages\django\__init__.py", line 3, in <module>
from django.utils.version import get_version
ModuleNotFoundError: No module named 'django.utils'
/r/django
https://redd.it/6chwky
reddit
Just installed django, but get ModuleNotFoundError when... • r/django
Traceback (most recent call last): File "C:\Users\X\AppData\Local\Programs\Python\Python36-32\Scripts\django-admin-script.py", line 11, in...
Rest Framework URL Config
I've set up rest_framwork in my Django app in an attempt to make an api for my project. Issue is I run into this error (AttributeError: 'RegexURLResolver' object has no attribute 'default_args')
when trying to run the app. Anybody else have this problem?
/r/django
https://redd.it/6cjyrt
I've set up rest_framwork in my Django app in an attempt to make an api for my project. Issue is I run into this error (AttributeError: 'RegexURLResolver' object has no attribute 'default_args')
when trying to run the app. Anybody else have this problem?
/r/django
https://redd.it/6cjyrt
reddit
Rest Framework URL Config • r/django
I've set up rest_framwork in my Django app in an attempt to make an api for my project. Issue is I run into this error (AttributeError:...
So atom, pycharm, and visual studio have a thing where you type partial word such as str, and it shows "started" or "substraction" for auto complete choices. Is there an addon, or other editor that also shows a short definition of each and quickly accessible?
Say you float a mouse over it or toggle a key while hovering one of the choices and it provides a short description with a hover tag.
Example here: https://www.w3schools.com/tags/tag_abbr.asp
/r/Python
https://redd.it/6ckjde
Say you float a mouse over it or toggle a key while hovering one of the choices and it provides a short description with a hover tag.
Example here: https://www.w3schools.com/tags/tag_abbr.asp
/r/Python
https://redd.it/6ckjde
W3Schools
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
Need Django REST Framework Suggestion
I am trying to achieve this request body and response body
POST /issues/
> {
"Issue": {
"title": "python",
"owner": "test",
"description": "test",
"status": "test",
"projects": "test"
}
}
GET /issues/
> {
"Issue": [
{
"id": 1,
"title": "test",
"owner": "test",
"description": "test",
"status": "test",
"projects": "test"
},
{
"id": 2,
"title": "test",
"owner": "test",
"description": "test",
"status": "test",
"projects": "test"
}, .... ]}
The code in views.py
class CreateView(generics.ListCreateAPIView):
queryset = Issue.objects.all()
serializer_class = IssueSerializer
def list(self, request):
queryset = self.get_queryset()
serializer = IssueSerializer(queryset, many=True)
return Response({"Issue" : serializer.data})
def create(self, request):
serializer = self.get_serializer(data=request.data['issue'])
serializer.is_valid(raise_exception=True)
self.perform_create(serializer)
headers = self.get_success_headers(serializer.data)
return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)
is there a better way to do this(ignore the tabs)?
/r/djangolearning
https://redd.it/6chhs5
I am trying to achieve this request body and response body
POST /issues/
> {
"Issue": {
"title": "python",
"owner": "test",
"description": "test",
"status": "test",
"projects": "test"
}
}
GET /issues/
> {
"Issue": [
{
"id": 1,
"title": "test",
"owner": "test",
"description": "test",
"status": "test",
"projects": "test"
},
{
"id": 2,
"title": "test",
"owner": "test",
"description": "test",
"status": "test",
"projects": "test"
}, .... ]}
The code in views.py
class CreateView(generics.ListCreateAPIView):
queryset = Issue.objects.all()
serializer_class = IssueSerializer
def list(self, request):
queryset = self.get_queryset()
serializer = IssueSerializer(queryset, many=True)
return Response({"Issue" : serializer.data})
def create(self, request):
serializer = self.get_serializer(data=request.data['issue'])
serializer.is_valid(raise_exception=True)
self.perform_create(serializer)
headers = self.get_success_headers(serializer.data)
return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)
is there a better way to do this(ignore the tabs)?
/r/djangolearning
https://redd.it/6chhs5
reddit
Need Django REST Framework Suggestion • r/djangolearning
I am trying to achieve this request body and response body POST /issues/ > { "Issue": { "title": "python", "owner": "test", ...
Do you use Cython?
I watched today Alex Orlov's PyCon 2017 presentation "Cython as a Game Changer for Efficiency" ([link](https://www.youtube.com/watch?v=_1MSX7V28Po)). I tried it years ago but I've never used it actually. Do you use Cython? It hurts portability but it can greatly improve efficiency.
/r/Python
https://redd.it/6cific
I watched today Alex Orlov's PyCon 2017 presentation "Cython as a Game Changer for Efficiency" ([link](https://www.youtube.com/watch?v=_1MSX7V28Po)). I tried it years ago but I've never used it actually. Do you use Cython? It hurts portability but it can greatly improve efficiency.
/r/Python
https://redd.it/6cific
YouTube
Alex Orlov Cython as a Game Changer for Efficiency PyCon 2017
"Speaker: Alex Orlov
Are you running a Web application? Do you suffer from CPU bottlenecks that slow down your growth? There's a tool that can easily fix all that, and then some. C++ knowledge not required.
Come learn how Instagram, the world's largest…
Are you running a Web application? Do you suffer from CPU bottlenecks that slow down your growth? There's a tool that can easily fix all that, and then some. C++ knowledge not required.
Come learn how Instagram, the world's largest…
Autopopulating grid layout?
I'm just getting into wagtail, getting back into webdev. Last time I was doing web stuff, there were no frameworks, so it is a bit of a learning curve for me.
I'm wondering if there is an easy way(i.e package or template) that would allow for a grid stye layout of stores/posts, which would auto update each time a new post was made, similar to the mroe popular news/blog sites like nerdist or whatever.
Or is this something that has to be built from scratch?
/r/django
https://redd.it/6clzqo
I'm just getting into wagtail, getting back into webdev. Last time I was doing web stuff, there were no frameworks, so it is a bit of a learning curve for me.
I'm wondering if there is an easy way(i.e package or template) that would allow for a grid stye layout of stores/posts, which would auto update each time a new post was made, similar to the mroe popular news/blog sites like nerdist or whatever.
Or is this something that has to be built from scratch?
/r/django
https://redd.it/6clzqo
reddit
Autopopulating grid layout? • r/django
I'm just getting into wagtail, getting back into webdev. Last time I was doing web stuff, there were no frameworks, so it is a bit of a learning...
CSRF Verification Failure on Localhost?
This is an extension on my last topic https://www.reddit.com/r/django/comments/6c1q2c/added_google_recaptcha_and_i_get_ssl_certificate/. I didn't really get a solution to.
I now tried a different technique and get a different error message than from all the other stuff I've done before. I followed instructions from this website on setting up stunnel: http://userpath.co/blog/a-simple-way-to-run-https-on-localhost/
and then used this command:
`HTTPS=on python manage.py runserver`
I get this message: https://pastebin.com/JXWVWNJq
My contact form html template has a csrf token
https://pastebin.com/Pcnmw3pA
Of course the major question is what am I doing wrong?
Second question is can https be run on localhost?
If I try https://localhost:8000 I get "This site can’t provide a secure connection localhost sent an invalid response." So I understand that the 403 is saying that my website is unsecure, but the redirect to google recaptcha is.
/r/django
https://redd.it/6chqsz
This is an extension on my last topic https://www.reddit.com/r/django/comments/6c1q2c/added_google_recaptcha_and_i_get_ssl_certificate/. I didn't really get a solution to.
I now tried a different technique and get a different error message than from all the other stuff I've done before. I followed instructions from this website on setting up stunnel: http://userpath.co/blog/a-simple-way-to-run-https-on-localhost/
and then used this command:
`HTTPS=on python manage.py runserver`
I get this message: https://pastebin.com/JXWVWNJq
My contact form html template has a csrf token
https://pastebin.com/Pcnmw3pA
Of course the major question is what am I doing wrong?
Second question is can https be run on localhost?
If I try https://localhost:8000 I get "This site can’t provide a secure connection localhost sent an invalid response." So I understand that the 403 is saying that my website is unsecure, but the redirect to google recaptcha is.
/r/django
https://redd.it/6chqsz
reddit
Added Google ReCaptcha and I get SSL:... • r/django
Hitting my head on recaptcha SSL: CERTIFICATE_VERIFY_FAILED Disclaimer: I’ve googled a few times and don’t fully understand the answers as they...
Structuring Python code
A while back there was a link posted aimed at beginners on how to structure Python code, files etc... Does anyone happen to have a link discussing this?
Thanks in advance
/r/Python
https://redd.it/6cmjj4
A while back there was a link posted aimed at beginners on how to structure Python code, files etc... Does anyone happen to have a link discussing this?
Thanks in advance
/r/Python
https://redd.it/6cmjj4
reddit
Structuring Python code • r/Python
A while back there was a link posted aimed at beginners on how to structure Python code, files etc... Does anyone happen to have a link discussing...
Django with Docker and Pycharm
Is anyone using a Django project inside a docker container in the Pycharm IDE?
I tried it but I can't figure out how to setup Pycharm for using the python interpreter.
Maybe someone could help me?
/r/django
https://redd.it/6cmy62
Is anyone using a Django project inside a docker container in the Pycharm IDE?
I tried it but I can't figure out how to setup Pycharm for using the python interpreter.
Maybe someone could help me?
/r/django
https://redd.it/6cmy62
reddit
Django with Docker and Pycharm • r/django
Is anyone using a Django project inside a docker container in the Pycharm IDE? I tried it but I can't figure out how to setup Pycharm for using...
Scala to consider syntax with significant indentation (Ticket by the Scala creator)
https://github.com/lampepfl/dotty/issues/2491
/r/Python
https://redd.it/6cmmlt
https://github.com/lampepfl/dotty/issues/2491
/r/Python
https://redd.it/6cmmlt
GitHub
Consider syntax with significant indentation · Issue #2491 · lampepfl/dotty
I was playing for a while now with ways to make Scala's syntax indentation-based. I always admired the neatness of Python syntax and also found that F# has benefited greatly from its optional i...
Facebook releases a new database OnlineSchemaChange tool written in Python
http://www.eversql.com/facebook-releases-a-new-onlineschemachange-tool-written-in-python/
/r/Python
https://redd.it/6cmfw8
http://www.eversql.com/facebook-releases-a-new-onlineschemachange-tool-written-in-python/
/r/Python
https://redd.it/6cmfw8
EverSQL
Facebook releases a new OnlineSchemaChange tool written in Python
Facebook’s online schema change tool’s goal is to alters a table's structure without blocking reads or writes to the database during execution.
The first version of Facebook OSC (OnlineSchemaChange) was released back at 2010 and was written in PHP. Last…
The first version of Facebook OSC (OnlineSchemaChange) was released back at 2010 and was written in PHP. Last…
Building a Reusable App -- question about templates
Hey Folks:
I'm considering building a reusable app that I could plug into a couple of my other projects. It would be an accounting app to handle all things accounting (revenues, expenses, invoicing, receivables, assets... etc etc).
My question is about the templates. If the app is to be as reusable as possible, how does one set up the templates? Should templates even be part of the app at all? Thinking of my other two projects that are already built, they use some custom CSS with specific classes, etc. so if I have templates as part of the reusable app, the templates would not follow those same standards. Likewise with my other project -- different CSS classes, etc.
So -- do templates normally form part of the reusable app? Should they be excluded? If there are parts of the app that need to be using templates, how should they be built so they are very reusable?
Any thoughts on that front?
/r/django
https://redd.it/6corzx
Hey Folks:
I'm considering building a reusable app that I could plug into a couple of my other projects. It would be an accounting app to handle all things accounting (revenues, expenses, invoicing, receivables, assets... etc etc).
My question is about the templates. If the app is to be as reusable as possible, how does one set up the templates? Should templates even be part of the app at all? Thinking of my other two projects that are already built, they use some custom CSS with specific classes, etc. so if I have templates as part of the reusable app, the templates would not follow those same standards. Likewise with my other project -- different CSS classes, etc.
So -- do templates normally form part of the reusable app? Should they be excluded? If there are parts of the app that need to be using templates, how should they be built so they are very reusable?
Any thoughts on that front?
/r/django
https://redd.it/6corzx
reddit
Building a Reusable App -- question about templates • r/django
Hey Folks: I'm considering building a reusable app that I could plug into a couple of my other projects. It would be an accounting app to handle...
Larry Hastings The Gilectomy How's It Going PyCon 2017
https://www.youtube.com/watch?v=pLqv11ScGsQ
/r/Python
https://redd.it/6cmslt
https://www.youtube.com/watch?v=pLqv11ScGsQ
/r/Python
https://redd.it/6cmslt
YouTube
Larry Hastings The Gilectomy How's It Going PyCon 2017
"Speaker: Larry Hastings
One of the most interesting projects in Python today is Larry Hastings' ""Gilectomy"" project: the removal of Python's Global Interpreter Lock, or ""GIL"". Come for an up-to-the-minute status report: what's been tried, what has…
One of the most interesting projects in Python today is Larry Hastings' ""Gilectomy"" project: the removal of Python's Global Interpreter Lock, or ""GIL"". Come for an up-to-the-minute status report: what's been tried, what has…
Whats the best way to create a weather heat map using python?
Send me your ideas on how to create a wether heat map as a little project.
/r/Python
https://redd.it/6cp9oy
Send me your ideas on how to create a wether heat map as a little project.
/r/Python
https://redd.it/6cp9oy
reddit
Whats the best way to create a weather heat map using... • r/Python
Send me your ideas on how to create a wether heat map as a little project.
Plotnine is a superior Python implementation of R's ggplot2
http://pltn.ca/plotnine-superior-python-ggplot/
/r/pystats
https://redd.it/6cq95e
http://pltn.ca/plotnine-superior-python-ggplot/
/r/pystats
https://redd.it/6cq95e
pltn.ca
Plotnine is the best Python implementation of R's ggplot2
plotnine is a new Python library that implements R’s ggplot2. It is a better implementation than ggpy, which was the best option until now for Python users. In this article I show a few examples comparing plotnine, ggpy, and ggplot2.
Multiple projects, shared auth, single sign-on
Im trying to determine how to best structure multiple django apps on subdomains, so they can share user account data. One user account works across 2 subdomains, ideally single-sign on.
I understand we can use SESSION_COOKIE_DOMAIN to share the session cookie, that part seems ok.
And I understand we could simply use shared user tables, and set user model to point to table of another project. But it seems we would want to share code between the projects. Should we have a separate User app in a third repo?
I have seen django-mama-cas , does anyone have experience with it? Or any alternatives?
/r/django
https://redd.it/6cp4gw
Im trying to determine how to best structure multiple django apps on subdomains, so they can share user account data. One user account works across 2 subdomains, ideally single-sign on.
I understand we can use SESSION_COOKIE_DOMAIN to share the session cookie, that part seems ok.
And I understand we could simply use shared user tables, and set user model to point to table of another project. But it seems we would want to share code between the projects. Should we have a separate User app in a third repo?
I have seen django-mama-cas , does anyone have experience with it? Or any alternatives?
/r/django
https://redd.it/6cp4gw
reddit
Multiple projects, shared auth, single sign-on • r/django
Im trying to determine how to best structure multiple django apps on subdomains, so they can share user account data. One user account works...
New Wireless Sniffer Tool Written In Python to Be An Alternative to Airodump-ng
https://github.com/M1ND-B3ND3R/BoopSuite
/r/Python
https://redd.it/6csfws
https://github.com/M1ND-B3ND3R/BoopSuite
/r/Python
https://redd.it/6csfws
Made a boilerplate for Django (1.11.1) projects using Django REST Framework (3.6.3)
https://github.com/buckyroberts/Django-REST-Boilerplate
/r/django
https://redd.it/6csqba
https://github.com/buckyroberts/Django-REST-Boilerplate
/r/django
https://redd.it/6csqba
GitHub
buckyroberts/Django-REST-Boilerplate
Boilerplate for Django projects using Django REST Framework - buckyroberts/Django-REST-Boilerplate