I have two question from bottle python web framework
Question 1. In my website http://localhost:8080/home
i am browsing via browse button to fetch excel file.i will process
excel file i want to show the data in same
http://localhost:8080/home page.
But when i google, they asked me to create template.
Do we have only option to go for template or any possibility to
display in the same home page
Question 2:
I created template file and able to show results in the template but
i style sheet is not reflected in the template.
i tried href =/static/style.css i tried href
=/app/static/style.css i tried like URL get_url('static',
Thanks Mani.
Well, If you are rendering anything, you definately need a template. Of course, you can create this template in a flexible way, but it's up to you.
When it comees to the second question, the url should be put in quotation marks. Compare
Related
I have a Python web app that uses Flask and Django (among other things). The app currently routes to quite a few HTML pages. A few of those HTML pages are forms that post to PHP files where the data is submitted to a db.
When launching with VSCode, all python and HTML files work great but the PHP file doesn't execute and obviously doesn't submit the data to the db. Conversely, when running the HTML/PHP files directly in Chrome, the data is submitted but the HTML form is no longer dynamic and the templates aren't successfully extended to the HTML file.
Is this goal even achievable? Should the PHP document be translated to a different language?
You've got two questions here- is it doable, and should you do it. The answer to the first is yes, it absolutely is doable- but the answer to the second is that you should not do it as it will be a maintenance nightmare and will introduce complexities into the system that you're probably going to want to avoid.
I´m new to web dev,
and I was wondering if it´s possible to make a website, that just need to present information of a company (HTML), in just one view.
Like rendering the entire bootstrap in one view.
Yes, you can serve your HTML code through a TemplateView.
So if your entire single page application sits in home.html you could definitely do this. But there is no point in using Django for only that purpose. You would rather want to serve your static HTML page from a classic web server like nginx or apache.
I don't know why would you want to do that.
You can use different html files which will be served as your website templates. You can also extend the files using a simple base.html file. This will help you if you want to open other links when people click on different links on the website.
See this example: https://github.com/singh1114/Djangosite/tree/master/duggal/webportal/templates/webportal.
For using this you have to know more about views and urls.
For making scrollable things, you need to know the concept of ids in HTML.
For example
http://yoursite.com/#your_name will try to find id your_name in the HTML. This way you can create scrollable things.
Here's the python code:
template = jinja_environment.get_template('index.html')
self.response.out.write(template.render(template_values))
However, I'd like to load index.html starting at the anchor tag below:
(wherein this anchor tag is in the index.html file)
<section> id="home">
How would i change the python code to do this?
As you can tell, I'm new, and currently working through the Google App Engine tutorials.
Thanks for your help!
I think that you are a bit confused. With jinja2 and Python code all you can achieve is to produce the page server-side. If you want to jump into a specific section within that page you should do that client-side by using JavaScript (example).
Let's supose you want acces your page at /yourpage and on home section. You could do this with a redirect:
YourHandler(RequestHandler):
def get(self):
self.redirect("/yourpage#home")
So you need to put the section id just after the "#" sign.
It worked for me at least on Google Chrome.
My website have submenus for sections. What I want to do is, when users click the submenu, the content changes accordingly. For example, if user clicks "Pen", the contents of the shall be list of pens, clicks "Eraser" , contents shall be eraser list.
How can I achieve this by using Django template and ajax? I know that I could retrieve the information as JSON data and parse it to update the div, but that requires a lot of work and I cannot use the Django template functionality.
I managed to pass the AJAX request to the server and process the list, but how can I return the rendered template as AJAX result?
Simply return the rendered template fragment. You don't need to do anything special. Your Javascript can then just insert it into the DOM at the relevant point.
I was not able to come up with a better title for this post, so if anybody does not find it appropriate , please go ahead and edit it.
I am using flask as my python framework, and normally I render templates doing somnething like the below:-
#app.route('/home')
def userhome():
data=go get user details from the database
return render_template("home.html",userdata=data)
Now I have a template name home.html in which I iterate over the values of "userdata" like userdata.name, userdata.age etc and these values take their appropriate spaces in the template.
However I am working on an application in which navigation is via ajax and no fall back if javascript is not available(basically the app does not work for ppl without javascript).
The navigation menu has say few tabs on the left ,(home,youroffers,yourlastreads). The right column is supposed to dynamically change based on what the user clicks.
I am unable to understand how I handle templating here. Based on what the user clicks I can send him the required data from the db via a json through an xhrGET or xhrPOST.Does the entire templating have to be handled at the server end and then transfer the entire template via an ajax call. I actually dont like that idea much. Would be great if someone could point me in the right direction here.
Now in the page that is loaded via ajax , there are some scripts which are present. Will these scripts work, if loaded via ajax.
You have two options: template on the server, or template in the browser.
To template in the server, you create an endpoint much like you already have, except the template only creates a portion of the page. Then you hit the URL with an Ajax call, and insert the returned HTML somewhere into your page.
To template in the browser, your endpoint creates a JSON response. Then a Javascript templating library can take that JSON, create HTML from it, and insert it into the page. There are lots of jQuery templating solutions, for example.
I would choose server side templating, because unless you find a JS library that handles the same templating language your code isn't going go be DRY.
In the home.html template, I'd do something like
<%extends base.html%>
<%include _user_details.html%>
... <% footer and other stuff%>
And keep the actual markup in _user_details.html. This way, for an AJAX request you just render the _user_details.html partial only.