简体   繁体   English

Django:如何让第三方网站访问服务器上的图像。(受限访问,即仅访问该文件夹)

[英]Django:How to let 3rd party sites access images on your server.(limited access i.e. only to that folder)

I am working in Django.I am trying to connect my website to Facebook. 我正在Django中工作,正在尝试将我的网站连接到Facebook。 What i want to do is 我想做的是

1)Send post_data 1)发送post_data

post_data = [('access_token',access_token), ('message', message), ('link', some_link),('picture',internal_server_path_of_image)

2) urllib2.urlopen(graph_url, urllib.urlencode(post_data)) 2) urllib2.urlopen(graph_url, urllib.urlencode(post_data))

What this should do is post that data on the facebook profile of a user. 这应该做的是将该数据发布在用户的Facebook个人资料上。 But i am unable to access "internal_server_path_of_image". 但是我无法访问“ internal_server_path_of_image”。 Is there anyway in which i can make a particular folder on my server available to the site ? 无论如何,我可以在服务器上使站点上的特定文件夹可用吗? ie the images on that folder should be accessible from outside. 即该文件夹上的图像应该可以从外部访问。 for eg I have folder site_name/project/images/photos.png on the server some_server.dreamhost.com/site_name/project/images/photos.png. 例如,我在服务器some_server.dreamhost.com/site_name/project/images/photos.png上有site_name / project / images / photos.png文件夹。 Now i want to access this image somehow. 现在我想以某种方式访问​​此图像。

Is the question clear ? 问题清楚了吗? or do I need to add a few things ? 还是我需要添加一些东西? Any help will be highly appreciated. 任何帮助将不胜感激。

I have come with a solution. 我有一个解决方案。 As people had pointed out that the imagefield gives us the url of the image. 正如人们指出的那样,imagefield为我们提供了图片的网址。 That was true, what i am doing now is passing that url. 没错,我现在正在做的就是传递该网址。 At that url i have written a controller method. 我在那个网址写了一个控制器方法。 This method simply renders the image and returns it. 此方法仅渲染图像并返回它。 This gives access to the facebook api to get the required image from my server. 这样可以访问facebook api,以从我的服务器获取所需的图像。

def test(request,name): 
   name = str(name)+".jpg" 
   url = "Users/admin/workspace/bolt/templates/media/images/photos/" 
   full = url+name image_data = open(full, "rb").read() 
   return HttpResponse(image_data, mimetype="image/png")

Hope this helps others 希望这对别人有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从第三方模块访问Django设置? - how to access django settings from 3rd party module? 如何在页面中访问第三方跟踪参数(通过Python)? - How can I access 3rd party tracking parameters within a page (via Python)? 如何将所有第3方库放在一个文件夹中? - How to place all 3rd party libraries at one folder? Django 1.8:如何在我当前的项目中使用我的第一个第3方Party? - Django 1.8: How do I use my first 3rd Party Fork with my current project? 如何在 Django settings.py 中获取第三方应用程序的路径 - How can I get path of 3rd party app in Django settings.py Django - 如何在不修改的情况下扩展第三方模型 - Django - how to extend 3rd party models without modifying 为什么Internet Explorer无法访问外部可访问的Django Development Server(即不在localhost上?) - Why can’t Internet Explorer access my Django Development Server that’s accessible externally (i.e. not on localhost?) Django:如何使用Jinja 2的第三方app模板标签? - Django : How to use 3rd party app templatetags with Jinja 2? 如何在Django中为第三方REST服务进行分页/分页 - How to do paging/pagination in Django for 3rd party REST services 如何在 Django 中管理与 3rd 方 API 的会话? - How to manage session with 3rd party API in Django?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM