I'm new to django and still trying to figure out logic. I watched a bunch of videos and I know how to create those examples but I'm not quite there. I'll explain what I want and maybe someone can explain to me a logic how to do, yes?
I created an app and inside an app I connected urls, settings, html and I have working site. Now I want to input data in django website, django to pass data to xlsxwriter script to create xlsx document, and to pass that document to user to download.
My logic: What I need now, is to create some kind forms (but not for registered users, it can use anyone who uses a website) to input data. Which forms are best? Than I need to pass () that data to function that are in views that will get an arguments from html page through some kind of forms, create document, and pass that to download button.
Related
I have created a simple app in Django using some tutorials, but it became very usefull and also scaled a lot.
What i have is a basic HTML table - prefilled with data from Model A.
At the end of the table there is Submit button, which just use some javascript to prompt a print window (to save the table[page] as PDF basically)
What i would like to do, is that when i press the Button to print, i would also pass some data from the table for example ModelA name and adress into a ModelB - which would serve as an statistic.
However i have used for this a simple tutorial, and therefore to display the table i used "DetailView" in views.py. This is my views.py file
class PrinterDetailView(DetailView):
model = Printer
template_name = 'printer_detail.html'
Is it possible to achieve this without redoing the whole site? i Found some people searching for simillar answers, but from that it seemed like i would have to redone whole app..
Thanks for your input!
I want to dynamically create multiple dropbox fields as I input the number of fields to be created.
For instance, there are 2 fields:
integer input field
dropdown menu
so when I input(let's say "4" in field 1) then 4 dropdowns should be created.
How should it be done? And upon submitting the form the same will be stored as a list in a database (flask is used at the backend).
Please guide.
Thanks in advance.
Flask is rather lightweight framework so to create fields dynamically use Javascript. Note nowadays its preferred to develop websites using some advanced JS library or 'framework' JQuery, vue, react etc. On backend you create a controller to save the data. Start with going though a tutorial to understand the procedure. https://www.youtube.com/watch?v=6N4OmsfwfdU . If you use WTF find a tutorial or discussion specific to WTF.
I have database created by django, but I can't print a text in my page from database. What function I will learn to make that.
You should have elaborated your question with your code samples. Before diving deep into any framework, you should go with tutorials. Django website itself provides you a step by step tutorial for that.
Here are few references:
https://www.youtube.com/watch?v=MEcXbeY4_DQ
https://docs.djangoproject.com/en/1.11/intro/tutorial01/
You will need to read the database in respective view function called in views.py in your app; and return the data as context to template so that you will be able to access them and print them.
So im trying to use my django installation to create a dashboard a combination of all the data from the 4 other models and views. For our use of django we mainly use it for stats so it's generally just pulling numbers out onto the main index page. Right now I have my index template set up as a redirect_to_template and it goes straight to a template (since everything is still static). Im trying to figure out if im going to have to create another app and pull in all the data to a new view & model for this dashboard page, or if I should create sub-templates if that would work to pull the data.
Thanks again!
I think you're better of with pulling the data by using ajax from your dashboard, it will be a better UX when you have a lot of data to fetch. For that you can use one of the known 3rd party apps for creating REST API or change your existing views to deliver json response as well.
To help anyone that has the question in the future. I ended up importing the apps such as
from status import Alert
context['list'] = Alert.objects.filter(All My Filters Here! (link below))[:8]
Then just for loop list in the template!
https://docs.djangoproject.com/en/dev/ref/models/querysets/
Hope this is helpful to someone else!
I have been trying to get my head around Django over the last week or two. Its slowly starting to make some sense and I am really liking it.
My goal is to replace a fairly messy excel spreadsheet with a database and frontend for my users. This would involve pulling the data out of a table, presenting it in a web tabular format, and allowing changes to be made through text fields and drop down menus, with a simple update button that will update all changes to the DB.
My question is, will the built in Django Forms functionality be the best solution? Or would I create some sort of for loop for my objects and wrap them around html form syntax in my template? I'm just not too sure how to approach the solution.
Apologies if this seems like an simple question, I just feel like there is maybe a few ways to do it but maybe there is one perfect way.
Thanks
The fastest way not to implement you own pages and to have a tabular view of your data is to use the django's built-in admin interface. It gives you sorting, filtering and search functionality and quick to start. You just need to define your models in models.py and setup the admin pages as described in the docs.
Normally the admin page is not used as a representation to users or customers but in the case you described it seems a clean and quick choice.
Exporting the excel sheet in Django and have the them rendered as text fields , is not as easy as 2 step process.
you need to know how Django works.
First you need to export the data in mysql in database using either some language or some ready made tools.
Then you need to make a Model for that table and then you can use Django admin to edit them