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
Django, DRF, and React Native together?

Hi, currently using the above to work on a senior project and I'm trying to build on my understanding of there tools working together and just wanna see if anyone can clear up some questions.

Have a signup and login screens so far, I've created a user model and the views and urls and the fields all match on both ends. I have a react native front that i want to use fetch to get the django urls i have defined. I'm using a serializer of my models to return a json. When I manage.py runserver I can navigate into the URL i have defined and the json response will show up in my browser. Now when I put that api into the fetch in the react native side I get an error about the server not being able to connect to dev server. so like fetch(localhost/app/user)

I tried to follow a few tutorials which got me far on both ends but now i want to glue them together. I read documentations but there's not much that discusses these working together in a version as detailed as I'd hoped for.

Does anyone have experience with these working together?

Do I need to change the ports for the django and/or react native server when they're running simultaneously on my local machine(for development purposes)? After I can get them linked, I create a user model on my react front it matches the user model on my django, how do I check that its inserted into my sqlite DB? Do I have to do anything on the django side to set up the db?

I know its a lot to ask without seeing my entire code, but if anyone has any tips on how to get this tool stack working together I'd appreciate it.

Thanks.

/r/django
https://redd.it/8d7ypo
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