Hiding Image in url and right click save option using Django - python

Iam using Django templates. I want to view image in webpages using django templates.But i want to restrict the image whenever we right click the image and click save as option and by taking html page source.
I have tried the link which is somehow similar which i want Can I use Django to prevent direct access to an image file? In Session Middleware, if image path, i redirected it to same view from where it called,
for gated in settings.GATED_CONTENT:
if path.startswith(gated) or path.endswith(gated):
is_gated = True
return redirect(reverse('my_view'))
By doing so, image is not displaying in webpage. Can Anyone help me?

The question you linked to doesn't do what you are asking (if I understand what you're asking correctly). You want to restrict people from being able to save an image that your site has served to their local machines (which can't be done).
The question you linked is about how to restrict image access to logged in users, probably to prevent hotlinking etc.

Related

Upload Images to Django starcross gallery from External Script

first time question.
I have been playing with Django and needed a photo gallery, and made a basic one, then found starcross gallery (https://github.com/Starcross/django-starcross-gallery). It works really nice and easy to put into my app, but from what I can tell its made for dragging and dropping images in, or by adding them from the django-admin page.
I need to be able to add photos from an external script. I haven't dealt with ImageField before. I was able to import the gallery.models in my api views file, and make it so I can POST and add those ok. But I have been pulling my hair out trying to get actual images to upload.
From looking around, I found I think how to do it with curl (I make my requests with curl then port it to python), and it gave me CSRF issues with a 403 Forbidden.
How can I upload an image and bind it to an album, externally with curl or Python?
Thanks

How to open dynamic links in new tab with web py framework?

I tried web.seeother("link"), but this does not open it in a new tab. Now I can generate a link with a _blank tag, but then the user has to click on the link separately that is separate button for generating the link and another button to follow that link. I want to perform both with a single click. A server side method to do this would be best.
I am using the web.py framework.
As the document says web.seeother() is used for redirecting a user to another page. So a more clear way for asking your question is: "how to make web.seeother() open a link in a new tab"?
As I have observed the documents, There is no way to do that on server-side.
Not a web.py issue. Cannot be done from server-side by any python or non-python framework, must be done in the Client.
From the client, you can set target="_blank" in the HTML, or use javascript with something like window.open(url). Javascript will allow you to set size and position of second window.

Is there any way to detect that an image url is not pointing to a non existent path using Django?

I have a website that sometimes points to images either locally or externally which do not exist. When displayed in the template they simply show no photo which looks bad. It would be ideal to completely hide the object in question if the image src is invalid.
Does anybody know how to accomplish this with Django. Or is there a better option out there?

saving event of opening url in database

Imagine post with url as a content.
Simplifying:
<post><link>http://blablabla.com/</link></post>
I'm looking for a magic function which allow me saving in database which url from posts has been clicked. For instance someone clicks the url and not only it opens in new window but also backround magic function saves this event in database. Can I the url and def at once? I have an app build in django. If there is anybody who knows how to bite it? If yes, could you help me?
I would say you have two options here. If it's an internal link (i.e. http://blablabla.com refers to your own site) you could have the logging functionality built into the receiving view.
Alternatively, you could modify the link to go through your own script which logs the request (urlencoded) before redirecting to the requested page (after decoding):
<post><link>http://blablabla.com/</link></post>
becomes
<post><link>http://mysite.com/log?page=http%3A%2F%2Fblablabla.com%2F</link></post>

Is there a way to save a captcha image and view it later in python?

I am scripting in python for some web automation. I know i can not automate captchas but here is what i want to do:
I want to automate everything i can up to the captcha. When i open the page (usuing urllib2) and parse it to find that it contains a captcha, i want to open the captcha using Tkinter. Now i know that i will have to save the image to my harddrive first, then open it but there is an issue before that. The captcha image that is on screen is not directly in the source anywhere. There is a variable in the source, inside some javascript, that points to another page that has the link to the image, BUT if you load that middle page, the captcha picture for that link changes, so the image associated with that javascript variable is no longer valid. It may be impossible to gather the image using this method, so please enlighten me if you have any ideas on this.
Now if I use firebug to load the page, there is a "GET" that is a direct link to the current Captcha image that i am seeing, and i'm wondering if there is anyway to make python or ullib2 see the "GET"s that are going on when a page is loaded, because if that was possible, this would be simple.
Please let me know if you have any suggestions.
Of course the captcha's served by a page which will serve a new one each time (if it was repeated, then once it was solved for one fake userid, a spammer could automatically make a million!). I think you need some "screenshot" functionality to capture the image you want -- there is no cross-platform way to invoke such functionality, but each platform (or desktop manager in the case of Linux, BSD, etc) tends to have one. Or, you could automate the browser (e.g. via SeleniumRC) to "screenshot" (e.g. "print to PDF") things at the right time. (I believe what you're seeing in firebug may be misleading you because it is "showing a snapshot"... just at the html source or DOM level rather than at a screen/bitmap level).

Categories