Should I implement the django rest framework above django? - python

Currently i have a Django blog website. (Fully functional)
This blogwebsite is something like a social media website...
I have read that django rest framework helps you to serialize your data.
Could I just check about the DRF:
Is serializing data important? Meaning to say what huge benefits would I get by having an additional django rest framework, and also any possible disadvantages?
Would it be very difficult to "add" the framework into my project. Eg does it require me to download a lot of things and change a lot of my codes?
Where does DRF stand, is it in the backend of frontend or is it more of like in the middle. How does it integrate into my current IT architecture: with django as backend, htmlcssjs as frontend and postgresql as database
Thank you!
Also if anyone is kind enough to share resources about DRF/ open to a short zoom sharing session on DRF, please feel free to contact at kimjoowon777#gmail.com

The idea of Django Rest Framework (DRF) is to simplify and cut down a lot of code from your Backend (aka API).
Django (standalone Django, not DRF) is a framework that allows you to build Backend (and also Frontend).
DRF is a cool library that allows you to create a backend with Django but a lot easier.
DRF allows you to create endpoints that allow you to manipulate the Data (ie. models) very quickly and with very little code.
The "Serialization part" of DRF just automatically (also magically) transforms your models data into a response (usually json) for the client and vice versa.
It does take some learning and coding to transform your current backend into DRF. but in my opinion unless you backend is really special, DRF can allow you to create an awesome API with very little code

Related

Is there any way to use a react js frontend to call flask security features?

I have an application which uses flask and flask-security-too in the rest layer. Since flask-security contains some nice, out-of-the-box solutions for user signup, registration etc. including some override-able views. I would really like to use it if possible.
However, I would instead like to plug in a react frontend to get the SPA things going. I read in the documentation for flask-security that the views are indeed possible to override but not sure if/how I would manage to get this working for a built react app?
To summarize my question: Can I use React.js still benefit from flask-security features?
Please read:
https://flask-security-too.readthedocs.io/en/stable/spa.html
basically - you will be using the JSON api rather than forms.

Serving Django MVC and Django Rest Framework from same Model

This may be an opinionated question but sorry I am too curious.
I learned to develop Django Model-View-Template websites ( multi page websites) and Django Rest Framework.
From the same Django Model can I create Rest API's and MVC templates together ?
I wanted to develop a Blog website that use session authentication and based on MVC architecture. The same server should create API's because the Mobile app for the Blog may consume the API's and use Token Authentication (using Djoser).
If I use same User model for session and token authentication, Can mobile blog app users use their username and password to access website version ?
Django REST Framework is just a collection of helpers to easily create HTTP endpoints that conform to REST behaviour, which mostly means conventions around GET, POST, PUT and DELETE. You could code all this behaviour by hand using default Django, DRF just makes it a lot easier. The end result are simply specific routes which accept input and return output in specific formats to/from models.
Of course you can use that in addition to normal Django Views. It's just a different interface to your models and other business logic. Authentication can be the same, but typically you use some sort of token authentication for the API; that ultimately depends on how the API is supposed to be used exactly.

Django, Angular, & DRF: Authentication to Django backend vs. API

I'm building an app with a Django backend, Angular frontend, and a REST API using Django REST Framework for Angular to consume. When I was still working out backend stuff with a vanilla frontend, I used the provided Django authentication to handle user auth- but now that I'm creating a REST based app, I'm not sure how to approach authentication.
Since all user data will be either retrieved or submitted via the API, should API authentication be enough? If so, do I need to remove the existing Django authentication middleware?
Right now, when I try to hit API endpoints on an early version of the app, I'm directed to what looks like the normal Django login form. If I enter a valid username and password, it doesn't work- just prompts to login again. Would removing the basic Django authentication prevent this? I want to be prompted to login, however I'm not sure how to handle that with these technologies.
The package django-rest-auth seems useful, and the same group makes an Angular module- but the docs don't go much past installation and the provided endpoints. Ultimately, I think the core of this question is: how do I entirely switch authentication away from what's provided by Django to something like django-rest-auth or one of the other 3rd party packages recommended by DRF?
edit: I made this comment below, but I realized that I need to figure out how combined auth will work. I'm not building a single page app, so individual basic pages will be served from Django, but each page will hit various API endpoints to retrieve the data it needs. Is there a way to have something like django-rest-auth handle all authentication?
To anyone that stumbles onto this question, I couldn't figure out how to make the hybrid approach work. Having Django serve pages that each contained API calls seemed OK, but I never saw any requests made to the API- I believe due to some other security issues. I'm sure it's possible, but I decided to go for the single page app implementation after all to make things simpler.

Flask-Admin vs Flask-AppBuilder

I am new to Flask and have noticed that there are two plugins that enable CRUD views and authorized login, Flask-Admin and Flask-AppBuilder.
These two features interest me along with nice Master-Detail views for my model, where I can see both the rows of the master table and the relevant details on the same screen.
Any idea which one to prefer? I see that Flask-AppBuilder has far more commits in Github, while Flask-Admin many more stars.
How to tell the difference, without spending too much time with the wrong choice?
I am the developer of Flask-AppBuilder, so maybe a strong bias here. I will try to give you my most honest view. I do not know Flask-Admin that much, so i will probably make some mistakes.
Flask-Admin and Flask-AppBuilder:
Will both give you an admin interface for Flask with bootstrap.
Will both make their best to get out of your way.
Will both help you develop Flask more Object Oriented style.
Will both let you override almost everything on the admin templates.
Will both support Babel.
Both inspired on Django-Admin.
Pros for Flask-AppBuilder:
Has a nicer look and feel (bias? maybe...).
Security has been taken care of for you, and supports out of the box, database, LDAP, OpenID, Web server integrated (REMOTE_USER), and in the near future OAuth too. Will let you extend the user model and security views.
Granular permissions, creates one permission for each web exposed method and action (you have to try it).
You can easily render Google graphs.
Smaller project, it's easier to request new features, and get your pull requests merged.
MasterDetail views and multiple views can be setup easily.
Backends: supports SQLAlchemy, MongoEngine, GenericInterface (you can integrate with your own builtin data still a bit beta).
Pros for Flask-Admin:
You have to assemble your own security (models, views, auth etc), it's ready though to integrate nicely with flask-security. This can be a pro or a con depending on what you want.
Builtin File Admin.
Bigger project with bigger community.
Backends: supports SQLAlchemy, GeoAlchemy, MongoEngine, Pewee and PyMongo.
Better support for MongoEngine (EmbeddedDocument, ListFields etc..).
On the overall i think Flask-Admin makes no assumptions at all like Flask, you have to code more, but this will let you be more free. Flask-AppBuilder makes some assumptions (on security), you will have to code much less, but some things can get on your way if your building very specific security models.
Hope this helps you and others, i tried my best to keep the bias out.
For me, master/detail is the major feature. That led me to use Flask AppBuilder to create ApiLogicServer:
With 1 command, create a database API, to unblock UI development. Also, a multi-page web app, to engage Business Users - early in the project. Declare logic with spreadsheet-like rules - 40X more concise than code, extensible with Python - for remarkable business agility.

Can Django be used for web services?

My friend said, "Pylons is so much better for web services."
My other friend said, "You can modify Django in a way to do exactly whatever you like."
In Django, what is necessary to be modified (urls.py? models classes? settings?) in order to do "web services" with APIs and REST and versioning, etc etc.?
Yes Django can be used for web services. Check out django-piston:
A mini-framework for Django for
creating RESTful APIs.
Piston is a relatively small Django
application that lets you create
application programming interfaces
(API) for your sites.
Yes, we use it directly. We have view functions that respond to some URI's with serialized JSON or XML objects instead of pretty HTML pages.
Absolutely.
Django is in fact made to be used on server side. But first you need to understand that it is a framework.
A framework is a set of tools which get the common activities done in web development (e.g Login or Sign up module).

Categories