How would I go about linking css and images to a template without routing it through bottle (#route('/image/') or #route('/css/')) and using a static_file return? because i am unable to link css normally (it cant find the css/image) and if i do it through static_file anyone can go to that link and view the css/image (IE www.mysite.com/css/css.css or www.mysite.com/image/image.png). Is there any way to get around this issue?
In order for a webbrowser to be able to download and render the css or image, it will either have to be part of your page (where people can view it by viewing the source of the page) or accessible at a URL.
So if you're trying to get around people being able to look at just your css or just your image, the answer is that there's no way around it.
see how to route to static files in bottle in the documentation, here: http://bottlepy.org/docs/dev/tutorial.html#tutorial-static-files
Related
I want to make a python bot that can interact with Symbolab. Here is an example. I have tried using the requests library and an example of the HCTI library to render the page as an image. Whenever I do this, the page looses its formatting. I am new to web scraping but I presume this is due to the css not being rendered as I was just grabbing the html. Is there I way that I can save an image file of a site like Symbolab in a way that renders the page like a web browser (all of the equations are readable etc)?
You are correct that the css is not rendered. When you use the requests library, you just get what you get for. If you look at symbolab's page, their css is found in <link href="/public/auto/main.min.css?110025" rel="Stylesheet" type="text/css"> inside the head of the html of the page.
If you want to use HCTI (which I assume is https://htmlcsstoimage.com/?), it looks like they accept an html parameter as well as a separate css parameter. So you could just have another request to https://www.symbolab.com/public/auto/main.min.css?110025 to get the CSS and use that with HCTI.
But this is only assuming there is no other CSS reference on their page and that this URL doesn't become invalid. To resolve this, you could scrape the html you received for CSS references and always get the most up to date links.
An easier solution might be to just use Selenium to programmatically control a browser, which will do all the rendering like if you were on a regular browser. Then you can take a screenshot of the page using Selenium still. Or even a picture of a specific element. See this answer
Hope this helps.
first time poster here.
I am just getting into python and coding in general and I am looking into the requests and BeutifulSoup libraries. I am trying to grab image url’s from google images. When inspecting the site in chrome i can find the “div” and the correct img src url. But when I open the HTML that “requests” gives me I can find the same “div” but the img src url is something completely different and only leads to a black page if used.
Img of the HTML requests get
Img of the HTML found in chrome's inspect tool
What I wonder, and want to understand is:
why are these HTML's different
How do I get the img src that is found with the inspect tool with requests?
Hope the question makes sense and thank you in advance for any help!
Maybe differences between the the response HTML and the code in chrome inspector stems for updates to the page when JS changes it . for example when you use innerHTML() to edit div element so the code you add will add to DOM stack so as the code in the inspector but it would have no influence on the response.
You may search the http:// in the begging and the .png or .jpg or any other image format in the end.
Simply put, your code retrieves a single HTML page, and lets you access it, as it was retrieved. The browser, on the other hand, retrieves that HTML, but then lets the scripts embedded in (or linked from) it run, and these scripts often make significant modifications to the HTML (also known as DOM - Document Object Model). The browser's inspector inspects the fully modified DOM.
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.
The problem is described in title. I have this template for a blog that I'm creating using Django.
When I open it normally, using double click over the HTML file, it looks like this:
But when I open it via url from the Django project, it looks like this
It only shows a green square (part of the css) but obviously can't open the css correctly.
Any idea to solve this?
In Django you don't open the HTML with double click on the file, you need to run the server first and open your site using the localhost (like you did in the second picture).
Judging by those images, are you sure you put the image in the static folder? In Django, the HTML files stays in the "templates" folder of your app and the css, javascript and images in the "static" folder.
If this answer doesn't help you, then you should post your code here, otherwise I can't find the problem.
I need to know the full url for the current page from within a Mako template file in Pylons.
The url will be using in an iframe contained within the page so it needs to be known when the page is being generated rather than after the page hits the server or from the environment. (Not sure if I am communicating that last bit properly)
Not sure if this is the Pylons way of doing things but ${request.url} seems to work for me.
I think you can use h.url_for('', qualified=True) to get the full URL.
Make sure you have imported url_for in your helper file: from routes.util import helpers as h
Have a look at http://pylonshq.com/docs/en/0.9.7/thirdparty/routes/#routes.util.url_for