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
Is there a way to make radioField within for loop ? if possible how to set the values for them?



/r/flask
https://redd.it/8d81jw
Adding a CMS solution to existing Django.

Can someone help me locate a CMS solution/add on the an existing standard Django system?

It seems everything I'm finding is a purely stand alone CMS system built on Django. What I have is an existing website that I want to add a managed blog to with a nice WYSIWYG editor for our marketing people.

If you can help point me in the right direction I greatly appreciate your time.

/r/django
https://redd.it/8d9b5w
[Ask Flask] Context_processor usage brings up a TypeError?

Hi, so I'm working on a website which allows users to make and delete posts. The delete function should be accessible using a link below said post, much like posts on Reddit, so I wrote this line in my index.html file:

<p><a href={{ delete_posts(post_id=post.id) }}>Delete</a><p>

The delete_posts function is here:

@app.context_processor
def utility_processor():
def delete_posts(post_id):
post = Post.query.filter_by(id=post_id).first()
if post != None: # This statement was added after the error was found, but it has no effect
db.session.delete(post)
db.session.commit()

When I run this I get the following error:

> TypeError: 'NoneType' object is not iterable

I was using the example on the flask website, so I'm expecting it has something to do with the database being used?

Here is a link to the full html file, and a .txt file containing the error.

https://gist.github.com/ModoUnreal/031741e6a8fe6277a786f11e6261c7f5

/r/flask
https://redd.it/8c1fiy
[AF] SQLAlchemy: Converting a query object to raw SQL & parameters and then executing it

I hope that it is OK to post this question here, although it is not strictly related to Flask. I couldn't find a better place to post it.

Context: Flask, SQLAlchemy and MySQL

I am looking for a way to convert a query object to raw SQL and parameters and save this in a dictionary, in order to be able to pickle dump and load the dictionary before executing the query. How can I achieve converting the query and then executing the text and parameters with SQLAlcehmy?

I'd be eternally grateful if anyone could point me in the right direction.

/r/flask
https://redd.it/8dewj6
Add a Blog to Django project using Wagtail

In this tutorial, we'll add a blog to your Django project, using Wagtail.

After you follow this tutorial, you'll have:

1. An independent CMS admin for you to manage your blog, coexisting with your classic Django admin.

2. A standard blog using a Bootstrap theme, on a `/blog/` URL.

3. Blog posts which support Markdown and Latex syntax.

[Add a blog to your Django project, using Wagtail](https://wagtail.io/blog/add-wagtail-blog-to-django-app/)


/r/django
https://redd.it/8deohd
JavaScripthon 0.9 has been released


I'm pleased to announce the release of version 0.9 of JavaScripthon!

JavaScripthon is a small and unobtrusive yet powerful
Python-to-JavaScript compiler for Python 3.5+ that targets ES6+
syntax.

Changes since the previous version:

- add a --source-name options to be used together with
--inline-map when using -s;
- move main repository to gitlab.com/metapensiero;
- add support for default export and import;
- add documentation for the JS() marker function;
- refactor of the JS AST nodes;
- fix path splitting and joining on Windows (thanks to Roman Yakubuk);

There are some new contributions in this release:

- [BrainBacon](https://github.com/BrainBacon) has made a [JavaScripthon loader for WebPack](https://github.com/Beg-in/javascripthon-loader);
- [icarito](https://github.com/icarito) has contributed support for JavaScripthon to the [python-webpack-loader for WebPack](https://github.com/martim00/python-webpack-loader);
- [icarito](https://github.com/icarito) has also [integrated JavaScripthon with Nuxt.js and Vue.js](https://nuxt-python.surge.sh);
- [chfw](https://github.com/chfw) has [integrated JavaScripthon into pyecharts](https://github.com/pyecharts/pyecharts) to allow
Python function translation.

For more informations se the project homepage at https://gitlab.com/metapensiero/metapensiero.pj

It's also mirrored on github at https://github.com/metapensiero/metapensiero.pj

/r/Python
https://redd.it/8dgoct
Efficiently searching large databases?

One of my favorite things about databases is that you're able to search through tons of data and find things quickly, but I'm not really familiar with best practices.

On discord, there is a search feature that seems pretty comprehensive. It goes through all of the messages in a server and finds every message with the phrase given. How is this implemented? It seems like something like this might be a heavy operation if there are a lot of messages.

/r/django
https://redd.it/8dh2z0
Flask Live Webcast with Miguel Grinberg

Hi everyone! This Saturday at 9am US/Pacific time I will be hosting a 2nd Flask live streaming event, for those interested. The topic is going to be the Flask request and application contexts. If you ever got those obscure errors about working outside of a request or application context and did not understand what that means, I will try to solve the mystery for you, using easy to follow examples.

The webcast will be streamed on youtube at https://www.youtube.com/watch?v=Z4X5Oddhcc8.

Obviously you will be able to watch the recording later if you miss it, but the nice thing about watching it live is that you can post questions and vote on questions submitted by others. In the second portion of the webcast I will answer as many questions as I can starting from the most voted.

Hope to see you on Saturday! If you want to watch the first live stream, which I did about a month ago, it's [here](https://www.youtube.com/watch?v=fft6IvL-y1g).

/r/flask
https://redd.it/8dgro1
Is Coalesce a good practice ?

I am trying to get some statistics about my data, min, max, average etc and sometimes it's possible that there are no data to aggregate on, so the result should be 0.0

With no data aggregation returns None, so I have been doing something like below:

products.aggregate(total_profit=Coalesce(Sum("profit"), 0.0)).get("total_profit", 0.00)

Is this a good practice ?

/r/django
https://redd.it/8djdq8
python3isbetter killed you with ump9.

/r/Python
https://redd.it/8dib1q
[template language] queryset indexing not working

hello,

here's my code

{% if entries %}
{% for entry in entries %}
<div>{{ entry }}</div>
<div>{{ entry.0 }}</div>
<div>{{ entry.1 }}</div>
{% endfor %}
{% endif %}

and here's what i'm getting

<QuerySet [<FichierCopie: FichierCopie object (1)>, <FichierCopie: FichierCopie object (2)>]>

<FichierCopie: FichierCopie object (2)>

<FichierCopie: FichierCopie object (2)>


-> entry.0 and entry.1 are giving the same element

what's is the problem here


/r/django
https://redd.it/8dl2nm
Advice on approach to research dashboard

Hi everyone. I'm currently working on a project, in which we're pulling from a server (json-format), based on user ids. The idea now, is to make somewhat of a research dashboard for people not familiar with python, where they can execute basic operations. Aside from actually retrieving the data and possibly converting it to a format that's more accessible (such as csv) for data-analytic purposes, I have several annotation scripts that may or not may be interesting for the researchers purpose. The dashboard's purpose, then, is to allow users to select the ids they want and export the data, and select which annotations they want to include, or load a local dataset and do annotations. My question is pretty simple: which python gui framework or other frontend method would you recommend for such an approach? I have a little experience with js on a fundamental level, that's about it.

/r/Python
https://redd.it/8dm99a
Choosing VPS for relatively simple news site

Hi everyone.

What should I look for when choosing a vps for a longread-focused website? The stack is nginx+uwsgi+django+wagtail, with a few celery tasks and psql database. Would it be reasonable to expect it perform well (hold up to 1000 simultaneous users) on a setup with 4 vCPU and 8 Gb RAM? The project has no comments or other form of inter-user communication and all the content is entered through admin panel.

/r/django
https://redd.it/8dmfuu
"Cannot add foreign key constraint" when creating test database for tests.

I have a database that works fine, I can interact with it normally through Django. When I try to run unit tests, I use the following command:

python3 manage.py test --settings appname.settings_test

But I get the following error when creating the database:

django.db.utils.IntegrityError: (1215, 'Cannot add foreign key constraint')

One of my tables does indeed have a foreign key relationship with another, so I'm assuming that the table with the foreign key field is being added before the table that it depends on.

How can I verify that this is the case, and how can I go about addressing this issue so that tables are executed in the correct order?

I've tried a few different fixes, such as re-ordering the apps with each model in the INSTALLED_APPS setting, but nothing I've tried has worked. Any help would be appreciated! I am happy to provide any other information!

EDIT: Full stack trace below. Note that I am deleting the old database at the beginning because I am running this command multiple times in a row, so it's deleting the failed database from my last attempt.

Creating test database for alias 'example'...
Got an error creating the test database: (1007, "Can't create database 'test_example'; database exists")
Type 'yes' if you would like to try deleting the test database 'test_example', or 'no' to cancel: yes
Destroying old test database for alias 'example'...
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python3.5/dist-packages/django/db/backends/mysql/base.py", line 71, in execute
return self.cursor.execute(query, args)
File "/usr/local/lib/python3.5/dist-packages/MySQLdb/cursors.py", line 250, in execute
self.errorhandler(self, exc, value)
File "/usr/local/lib/python3.5/dist-packages/MySQLdb/connections.py", line 50, in defaulterrorhandler
raise errorvalue
File "/usr/local/lib/python3.5/dist-packages/MySQLdb/cursors.py", line 247, in execute
res = self._query(query)
File "/usr/local/lib/python3.5/dist-packages/MySQLdb/cursors.py", line 411, in _query
rowcount = self._do_query(q)
File "/usr/local/lib/python3.5/dist-packages/MySQLdb/cursors.py", line 374, in _do_query
db.query(q)
File "/usr/local/lib/python3.5/dist-packages/MySQLdb/connections.py", line 277, in query
_mysql.connection.query(self, query)
_mysql_exceptions.IntegrityError: (1215, 'Cannot add foreign key constraint')

/r/django
https://redd.it/8dofs3