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
Update datapoint in Postgress

Hi! I'm new to flask and Postgres. I want to update a column based on user input. Should I create a separate get and post methods or use my existing ones?

​

I want to update the count of an existing entry.

​

@app.route('/')
def get_exams():
# fetching from the database
session = Session()
exam_objects = session.query(Exam).all()

# transforming into JSON-serializable objects
schema = ExamSchema(many=True)
exams = schema.dump(exam_objects)

# serializing as JSON
session.close()
return jsonify(exams.data)


@app.route('/', methods=['POST'])
def add_exam():
# mount exam object
posted_exam = ExamSchema(only=('title', 'description', 'count'))\
.load(request.get_json())
exam = Exam(**posted_exam.data, created_by="HTTP post request")

# persist exam
session = Session()
session.add(exam)
session.commit()

# return created exam
new_exam = ExamSchema().dump(exam).data
session.close()
return jsonify(new_exam), 201

​

/r/flask
https://redd.it/axgl8j
[P] Ever wondered how to use your trained sklearn/xgboost/lightgbm models in production? We developed a simple library which turns your models into native code (Python/C/Java)

Imagine that you trained your super accurate model using your favorite tools (Python/sklearn/xgboost/etc.) and now the time has come to deploy your model to production for the greater good.

But consider the following scenarios:

* What if your production environment has no Python runtime?
* What if your model should make instantaneous predictions right on a microcontroller device without sending data to a remote server?
* What if prediction speed is a concern too?

This where m2cgen comes in handy. It's a library that generates Java/Python/C code from trained ML models.

Check it out: https://github.com/BayesWitnesses/m2cgen/


/r/MachineLearning
https://redd.it/axdirb
[AF] sqlalchemy password authetication failed for user "USERNAME". Confused as to what password is being used here.

Hi, so I am trying to get the backend for my website running using postgres alongside Flask. I have the following URI:

"postgresql://username:password@localhost/websitename"

So the problem being presented to me is the password. Do I have to input my actual linux system password into the password field or the postgresql password. I'm sure it's the latter however if that were the case I'd then need to find out how to gain access to this password as I do not remember setting one. Any help is greatly appreciated.

/r/flask
https://redd.it/aximdk
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/axljrp
Ordering by primary key

How do you order by a specific field, I used primary key as an example. I'm confused as to where this goes when using Classed Based Views. I have tried this but it's not doing what I expected:

from django.shortcuts import render, redirect
from django.template import RequestContext
from django.views.generic import View,TemplateView,ListView,DetailView
from . import models


class TestPageView(ListView):
context_object_name = 'categories'
model = models.Category
template_name='category_list.html'

ordering = ['id']

When first learning, using function based views it was easy to just add .order\_by, but not sure where to put this in CBVs.

​

/r/djangolearning
https://redd.it/axmvco
Mind sharing an open source repo that showcases a well organized Django Rest Framework?

I've starting to dip my toes into building an API and find that looking over code can be helpful. Any direction here would be greatly appreciated.

/r/djangolearning
https://redd.it/axsa1m
Complete Web Application for Startup Written in Flask



Recently I created [Chronos](https://www.chronosevents.com/), a online meeting and event scheduling platform, written entirely in Python, powered by the Flask web framework. I created Chronos with the goal of reducing time wasted scheduling meetings, increasing teams’ scheduling coordination, and enabling meeting creators and team leaders to select optimal meeting times.

I created Chronos as an alternative to the large number of email chains I racked up while trying to schedule meetings with other members of project teams at my university, and since then, I have added a large number of features to streamline the overall meeting scheduling process. The minimal approach of Flask makes it much easier to focus on the actual design of the site and its features and is an extremely valuable part of the development.

I would appreciate any comments or feedback you may have!

/r/Python
https://redd.it/axm8y5
Anyone else find Web development boring due to CRUD

Recently I've been actively learning and developing a website for a family member in Flask. The website includes, login, gallery upload and delete, adding blog posts, email verification, and other stuff. With all this, my final part of the eCommerce store and I'm done.

​

But throughout this whole process I've been getting more and more bored due to the nature of everything seems repetitive. In my eyes all web development from my experience has been just CRUD, (create, read, update, delete).

Am I doing something wrong, or does anyone share the same experience?

/r/flask
https://redd.it/axob5v
Web Development in Python with Django. 15 Videos ~ 4hours
https://www.youtube.com/playlist?list=PLhTjy8cBISEpXc-yjjSW90NgNyPYe7c9_

/r/Python
https://redd.it/axn7rv
User login system in MongoDB using Flask?

The Flask Mega Tutorial that uses SQLite, MySQL or PostgreSQL (via Flask-SQLAlchemy) as backend, and Flask-Login as user management system.

I want to mimic this, but with MongoDB as backend, but all I'm finding is a huge rabbit hole with more options than I could ever dream of. I tried a few things here and there, but it's pretty hard to get the basic functionality working. A few questions:

* Does it still make sense to use Flask-login and create classes for User and Post? If yes, what do I inherit from aside from UserMixin?
* I've also looked into JSON Web Tokens combined with jsonschema, but I'm not sure how to translate Flask-login's classes to this. Is there any way to say this is "better" (e.g. more secure, ) than Flask-Login?
* Do Flask-PyMongo and Flask-MongoEngine have the same functionality?
* Just thinking outside the box: is it a good idea to have the login system in an RDBMS and another part of the data in a NoSQL DMS?

/r/flask
https://redd.it/axwypa
[AF] Using flask_jwt, how can I redirect after successful authentication?

I hope this isn't too silly of a question. So if a user goes to /auth, and they successfully authenticate, I want to redirect them to another resource so I can log their IP address. So I'm thinking I need to redirect after /auth to something else like /ip and log their IP at that resource.

Does anyone have any insight they could offer? Thanks!

/r/flask
https://redd.it/axuuqi