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
Separate Project, same database

I have a django project which needs some infinatly looping background tasks. Because I want to decouple this from my webserver (for scalability among others) I want to create a separate project that handles these backgrounds threads, where the projects will communicate over an message broker like RQ. here's the catch, both projects need access to the same database. Now I have two options. Either share the database(my prefered option).
Or keep 2 separate databases in sync(potential horror).
for the first option I would love it if I could import the models I defined in my django models, so I don't have to worry about keeping my database models in sync over two projects, and not have to worry about writing one database in sqlalchemy and the other in the normal django orm.
Any suggestions?



/r/django
https://redd.it/8fzesc
Export FLASK_APP only works sometimes

Hi all,

I am running into an issue where export FLASK_APP will sometimes work and other times doesn't.

Initial Steps:

1. Git clone https://github.com/level09/enferno and cd enferno
2. create virtual env
3. Brew Install mongodb and start it
4. install requirements.txt
5. npm install

Now if I do this:

1. export FLASK_APP=enferno.py
2. flask run
3. printenv FLASK_APP (this prints enferno.py)

I get error: ModuleNotFoundError: No module named 'enferno'

If I do this instead:

1. export FLASK_APP=run.py
2. flask run
3. printenv FLASK_APP (this prints run.py)

I get error: ModuleNotFoundError: No module named 'enferno.app' (which is logical, it cannot "see" enferno yet)

But if I repeat Initial Steps again in a different directory, running export FLASK_APP=run.py works!
I get the following:

(venv_enf2) 192-168-1-3:enferno user$ flask run
* Serving Flask app "run"
* Forcing debug mode off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

I did not do anything different between the two directories, but both has different outcomes. Is there a flask dump I can get and read what's wrong with it?

In both directories I used the same virtual environment.



/r/flask
https://redd.it/8fzo2i
JavaScript integration with flask

Hey there,
I currently want to integrate my frontend with my python code and decided to use flask for the it. I tried jsonify() to create a jason object and send it to JavaScript but it doesn’t seem to work. Any ideas of what could go wrong or any material which would help in this integration.
Thank you.


/r/flask
https://redd.it/8fu9h9
How and why does JupyterLab depend on Node.js?

I installed the Matplotlib Jupyter widget, and found out it had Node.js as a prerequisite. [Link to instructions](https://github.com/matplotlib/jupyter-matplotlib)

Why? How does JupyterLab use Node?

Thank you.

/r/IPython
https://redd.it/8g2tic
Using flask-oauthlib in production or authlib

Hi all. I wanted to use flask-oauthlib in a website I'm building, and got it working last night. However, I noticed that the front page of the project has a warning to use authlib instead.

Are people using flask-oauthlib in production? Are you planning to migrate to authlib?

flask-oauthlib page, note the warning:

https://flask-oauthlib.readthedocs.io/en/latest/


/r/flask
https://redd.it/8e1u1q
Is there a way to add "Save and Add Another" button in crispy forms?

In Django admin there is an option Save and Add Another. How can similar function be added into crispy forms, so that entry from the first submitted form is kept?

/r/django
https://redd.it/8g7fei
python.org is down??

I'm getting:

503 Service Unavailable
No server is available to handle this request.

Anyone know who runs the server and when it can be fixed, I'm trying to download python on a new pc.

/r/Python
https://redd.it/8g7ek6
Learning Python in the Times of Innovation

/r/Python
https://redd.it/8g7nmk
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/8g8qcv
Questions about models

Hey there!

I started out with Django and followed some tutorials. I do know some things about databases but not too much.

My questions:
Let's say we have two models.
1. Bookstore
2.Book

Does bookstore refer to a lot of book ojects
Or
Does a book refer to a bookstore object?

Thanks in advance!

/r/django
https://redd.it/8g9rge
How to pass data from a button in the html page to a database?

I have to code a page that has a question, and 3 options to answer.
I have a page that display the questions and the 3 answers of every question, the questions are already stored in the database. Now my problem is how can I save the user choice for that specific question?
I have created a model to save the user choice, the user id, and the question id. But I'm having trouble to get witch button the user clicked for the answer.

#Here is the model
class UserVotes(models.Model):
id_user = models.CharField(max_length=10)
id_question = models.CharField(max_length=10)
choice_user = models.CharField(max_length=10)

#Here is the view
class QuestionListView(generic.ListView):
model = Question

def voteQuestion(request):
if 'Yes' in request.POST:
idQuestion = request.question.id
idUser = request.user.id
p = UserVotes(id_user=idUser, id_question=idQuestion, choice_user=1)
p.save()
elif 'No' in request.POST:
#same thing, the difference is the value of choice_user will be 2.

#the url.py
url(r'^question/$', views.QuestionListView.as_view(), name='question'),

#the html page
<button type="submit" name="Yes">Yes</button>
<button type="submit" name="No">No</button>

I've got several errors, the last one that came up is a http 405 error, method post not allowed.
If someone can help please, I've spend 2 nights and 1 day on this already haha. Thanks!!

/r/django
https://redd.it/8gae5m
RabbitMQ Disconnects

I'm using RabbitMQ(pika) and django on windows, and after the socket sits idle for some time, it disconnects. I allready tried : setting the connection parameter "blocked_connection_timeout" to none.

I also tried check if the connection was open and if not, reconnect, but this always leads to an ConnectionResetError.

Any ideas?

/r/django
https://redd.it/8gbknf
[AF] Which frontend framework works best with Flask?

/u/Cran3kill inspired me to ask [the same question](https://www.reddit.com/r/flask/comments/8ft6e9/which_front_end_with_flask/) he did yesterday with some additional information. All the answers like
> react!

or

> jinja with react was a pain

has no value without a context, so I give you one.


--------------------------------------------------------


So I'm building my data visualization/scrollytelling blog. It's a side project for myself, so I'm free to choose anything I want, but I have no idea what I want.

I know I will be experimenting with d3.js and many other libraries, but I have no idea where to begin with the *general* front-end. I know I can set up basic frontend with the Flask itself, but I want to learn how to separate backend from the frontend completely.

I've used JS and jQuery before in WordPress but that's that. I'm tired of watching all these comparisons of Angular vs React vs Vue. I don't really understand what's the difference and I just need to pick one, create a working environment and play around with d3.

This question may seem off-topic but it's really hard to decide **which framework works best with Flask** when you have no experience with a frontend at all. I've used the search tool, there are some questions about certain frontend frameworks but there's no general one and almost all of the github examples are dead.

How I see it:

On my VPS, EC2 etc. I run at least two servers:
Backend server: nginx -> uwsgi or gunicorn -> Flask (maybe with celery, also caching DB responses here).
Frontend server: ??, usually fetches data from Flask endpoint

Request - Respons cycle.
client -> domain -> dns -> frontend **??** -> server (Flask-RESTful etc.) -> frontend drawing library from db response or cached response -> client.

So I believe I need JS framework to do some routing and provide this 'look and feel' before d3js draws something on it.
I know I could've done that with Flask and Bootstrap, but once again, I want to separate frontend from backend in order to learn JS and how to structure an app like that.
I want it to be fast and light. I don't need *the newest* or *the best*. I probably don't want it to have all the tools in the world since that's why I dislike Django.

I really can't decide on my own. It requires way too much experience to know which one to pick and it seems like frontend battle never ends. Your advice and examples are greatly appreciated.

### Edit: I made a full circle a couple of times and I've decided to pick **vue**. I like its learning curve, components approach, origin and this [udemy course](https://www.udemy.com/vuejs-2-the-complete-guide) along with documentation should cover everything I need. Thanks y'all for help.


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