I was wondering, my team and I are considering using Django with Dash and React to build our application!
Django - backend
React - frontend
Dash - dashboards (also frontend)
So one thing I was trying to find out how to do but couldn’t is using pure HTML in a Django template,
create an element, give it an id, and use that element inside a dash callback.
for example:
inside an HTML file I would have:
inside the python dash file, we will have a callback returning value to that element
Output(“hello”, “children”)
Anyone knows a way to do this? / a repo with an example would be awesome!
Related
I have started learning DRF just a while ago and had a little question -
how can I code one API that will return HTML for the site that I am currently working on and return JSON format for other "clients"(e.g. mobile apps, desktop, etc)?
I have tried to search for this information, but didn't found any answering content.
The only way I see is to create default Django views for the site and create separated API's for other requests. Can anybody tell me if I am right and need to do so, or there is some code that is solving my problem?
Ultimately, you can think of it as a whole separate set of views, urls and instead of models you have a serializer. Within you're app you can create an API folder. Within that directory you will need to have an '_ _ init _ _.py', 'urls.py', 'views.py' and a 'serializers.py'. Its analogous to creating a standard url, view, model structure to display an HTML page, but without the HTML template. Make distinct urls for the serializers too. For example for login do something like this:
path('my_app_api/login', serializer_view)
Youtube has tons of videos if you search django rest framework
I am new to django and have been working on a project where i need to send regular mails to my clients from different modules in my django project.
I wanted to know if there is any provision in django using which i can create a reusable component which can be used globally in my project.
The purpose is to create a mail sending function using a third party api and to call it from anywhere in my application just by passing the required parameters.
Assuming that you have a single django app in your project, you could define all your reusable methods inside a methods.py file in your app folder and then import it to use the functions.
If you have multiple apps, Then define create this methods.py in one of your app. Now lets say your project name is coolprojectname and the name of app which has methods.py is appwithmethodsscript, then you can use
from coolprojectname.appwithmethodsscript import methods
Reference
Django follows the rules of python.
As such, you can define a function anywhere, and import it wherever you want to use it.
The only condition for this to work is to have your packages following the right structure (i.e. a directory that has an __init__.py file)
I have just started looking into using angularjs. I haven't done much front end development before and struggling to get my head around what handles what.
Would I be correct in saying that all I would use django for would be to create my models, REST api's and urls pointing to my api.
Would I no longer need to create views.py?
I'm not sure where to begin, as in do I start working towards PHP, Ruby or what, but here is what I'd like to do:
I have a Python script that takes a pre-formatted Excel document and using xlrd and Django, I output a nicely formatted HTML page, based on a template HTML page.
But currently on my team, I'm the only one that can use this Python script because our setups, and I'd like to simplify the process by creating a web app that has a couple drop down menus to specify which script to run, then let me upload the .xls file, at which point the HTML file is automatically generated and a download link is created or the HTML file is spit out somehow.
Does anyone have any guidance as to how I should even begin this project?
I would suggest having a good read of the django docs, and probably working through the tutorials.
Django's documentation is very good.
If you just want to hack at the code you've got then probably read the following to get a very basic overview of some core django functionality -
url dispatcher
views
models
forms
templating
With your app, the url dispatcher will pass the request to a view which will use a template to render your excel document.
You want a form to handle your user parameters and a single view to render and process the form and also render the excel template.
I'm using Django for my site and trying to incorporate backbone.js. Backbone encourages using Tastypie - but I would rather not. Is there a way to use backbone.js and django without tastypie? Are there any examples out there of how to do this?
I've been were you are. Needed to just make a custom API for backbone to read for the specific instances.
All that really means, is making custom views in your views.py and attaching them to custom urls in urls.py for backbone. Your views will have to return a JSON version of the object or objects
So you end up with friendly looking urls that backbone likes
For example if I had a model of boxes and I want to write a url and a view that sends all the boxes in my database to my frontend delivering them to backbone - I could make a url like this /api/v1/box/all/ really anything you want. In your view you just need to remember to return JSON.
Remember - you need update views to to update from backbone syncings (tastypie PUTS)
something like /api/v1/box/3/update?updatedinfodata
Let me know if you would like me to expand or show some code.
It is possible to bot use TastyPie and just build your own API.
You just need to know Backbone sends to the API and data it expects to receive.