是否可以在 Django视图中显示PDF文件,而不是让用户下载它来查看它?
如果有可能,它会怎么做?
这是我到目前为止 -
@login_required
def resume(request, applicant_id):
#Get the applicant's resume
resume = File.objects.get(applicant=applicant_id)
fsock = open(resume.location, 'r')
response = HttpResponse(fsock, mimetype='application/pdf')
return response
Run Code Online (Sandbox Code Playgroud) 如果我正确理解Big-O表示法,k应该是算法效率的恒定时间.考虑到需要一个可变的时间,为什么要考虑一个恒定的时间O(1)而不是O(k)?线性增长( O(n + k) )使用此变量将时间向右移动一段特定的时间,那么为什么不等同于常数复杂度?
我创建了一个Django网站,需要一个cookie来存储和从网站的任何部分读取.它的javascript在我需要它的每个部分,但由于某种原因,cookie本身单独存储每个页面.例如,如果cookie在一个页面上等于"set",则可能在另一个页面上未定义.这是我用来创建,获取和读取cookie的代码(当按下每个页面上的特定按钮时,调用"createBannerCookie()"方法) -
<script type="text/javascript">
$(document).ready(function() {
$('#banner').hide();
checkBannerCookie();
});
function createBannerCookie()
{
$('#banner').hide();
var exdate=new Date();
exdate.setDate(exdate.getDate() + 3);
var c_value=escape("set") + ((exdate==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie='banner=' + c_value;
}
function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
x=x.replace(/^\s+|\s+$/g,"");
if (x==c_name)
{
return unescape(y);
}
}
}
function checkBannerCookie()
{
var banner=getCookie("banner");
if (banner!=null && banner!="")
{
$('#banner').hide();
}
else
{
$('#banner').show();
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
有什么建议?