我在views.py中有一个函数,在某行我发出一个id的GET请求.一旦我获得了id,我想加密该id,然后再解密.所以我需要两个功能
def encrypt(id):#let say the id is 100
#do something
return encrypted_id # 6-digit let say 985634
def decrypt(encrypted_id): # Here enter 985634
#do something
return decrypted_id # i should get 100
Run Code Online (Sandbox Code Playgroud)
我已经阅读了很多帖子,但没有找到一种简单而干净的方式在我的views.py中应用它.这里我学到了什么
sha1:你不能解密(为加密实现)Mee 2 M2.AES它处理16位数的8位数的倍数
我试图生成6位数的随机数,但这个想法也没有用.任何人都能说出如何做到这一点的方法吗?提前致谢
{% for x in featured %}
<li class="panel">
<h3>
{% if x.title|length > 12 %}
{{x.title|slice:":12"}}...
{% else %}
{{x.title}}
{% endif %}
</h3>
<h4>
{% if x.details|length > 30 %}
{{x.details|slice:":30"}}...
{% else %}
{{x.details}}
{% endif %}
</h4>
<p class="btnlinks">
<i>noch <span>{{x.free_lots}}</span> lose</i>
<a href="{{base_url}}ProductDetails/?lotid={{x.lotteryid.0}}" class="btn">zuR verlosung</a>
<a href="{{base_url}}ProductDetails/?lotid={{x.lotteryid.0}}" class="mainlinkto"><img src="{{ STATIC_PREFIX }}images/base/arrowyellow.png" /></a>
</p>
<p class="slids"><img src="data:image/gif;base64,{{x.picture}}" ></p>
</li>
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
我想翻译zuR verlosung,noch,在模板中丢失.我在模板中如果我使用trans或block trans它会显示我错误说
Invalid block tag: 'blocktrans', expected 'empty' oder 'endfor'
Run Code Online (Sandbox Code Playgroud)
提前致谢
大家好,因为我在 Django 的学习阶段,所以支持我。我必须在 django 中生成 pdf 报告。我希望应该从数据库中选择详细信息并显示在 pdf 文档中。我正在使用报告实验室。现在看看代码
def pdf_view(request):
response = HttpResponse(mimetype='application/pdf')
response['Content-Disposition'] = 'attachment; filename=hello.pdf'
p = canvas.Canvas(response)
details = Data.objects.all()
print details
p.drawString(20, 800, details)
p.drawString(30, 700, "I am a Python Django Professional.")
p.showPage()
p.save()
return response
Run Code Online (Sandbox Code Playgroud)
现在作为学习示例,我在模型中创建了两个字段
class Data(models.Model):
first_name = models.CharField(max_length =100,blank=True,null=True)
last_name = models.CharField(max_length =100,blank=True,null=True)
def __unicode__(self):
return self.first_name
Run Code Online (Sandbox Code Playgroud)
我希望在 pdf 文档中它应该显示我通过管理员填写的任何名称,但它给了我错误
'Data' object has no attribute 'decode'
Request Method: GET
Request URL: http://localhost:8000/view_pdf/
Django Version: 1.3
Exception Type: AttributeError
Exception Value:
Run Code Online (Sandbox Code Playgroud)
我想从数据库中提取详细信息并显示在 …