从UI上传文件后,如何使用/ opt/files /中的当前时间戳创建新目录,并将上传的zip文件复制到此目录,并将zip文件解压缩到新目录中并维护新目录名称在变量中
def upload_info(request):
if request.method == 'POST':
file=request.FILES['file']
dir = "/opt/files"
file_name = "%s/%s" % (dir, file.name)
form = UploadFileForm(request.POST, request.FILES)
try:
handle_uploaded_file( file_name , file )
def handle_uploaded_file(file_name,f):
destination = open(file_name, 'wb+')
for chunk in f.chunks():
destination.write(chunk)
destination.close()
return
Run Code Online (Sandbox Code Playgroud) 我正在使用django 1.5
我能够在生产中提供文件,因为它是在apache级别处理的.这是我的httpd.conf文件:
<VirtualHost *:80>
WSGIScriptAlias / /home/membership/membership/wsgi.py
Alias /static/ "/home/membership/static/"
<Directory /home/membership/static>
Order deny,allow
Allow from all
</Directory>
<Directory "/usr/lib/python2.6/site-packages/django/contrib/admin/static/admin">
Order deny,allow
Allow from all
</Directory>
<Directory /home/membership/membership>
<Files wsgi.py>
Order deny,allow
Satisfy Any
Allow from all
</Files>
</Directory>
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
这在生产中很好用,因为 Alias /static/ "/home/membership/static/"
当我尝试在我的本地开发环境中运行应用程序我不能让它为静态文件我刚刚得到一个页面没有找到404错误.我猜这是因为当我在本地开发时,请求直接进入开发服务器,因为没有使用apache.
我在/static/me.png有一个文件.
是否有某些地方我应该指定在开发中提供静态文件?
运行python manage.py collectstatic
时似乎只收集管理员应用程序的静态文件.我有一个文件直接在我试图服务的/ app/static目录中.
我有一个Django
应用程序(我相当新,所以我正在尽力了解细节),我希望将 url 端点重定向到另一个文件夹(应用程序)中的静态 html 文件。
我的项目文件层次结构如下所示:
docs/
- html/
- index.html
myapp/
- urls.py
Run Code Online (Sandbox Code Playgroud)
我的urls.py
样子:
from django.conf.urls import patterns, include, url
from django.views.generic import RedirectView
urlpatterns = patterns('',
url(r'^docs/$', RedirectView.as_view(url='/docs/html/index.html')),
)
Run Code Online (Sandbox Code Playgroud)
但是,当我导航到 时,http://localhost:8000/docs
我看到浏览器重定向到http://localhost:8000/docs/html/index.html
,但该页面无法访问。
是否有任何原因导致应用程序在这样的重定向中/docs/html/index.html
无法使用?myApp
如果有人指点,我们将不胜感激。
我正在寻找购买机票,我必须在http://页面输入我的信用卡详细信息,如下所示:
如果我查看源代码,这实际上是一个带有HTTPS源的iframe,所以这实际上是安全的,但是一个非技术娴熟的用户无法知道这一点.显然,这太可怕了(即使是精通技术的用户).
现在,我的问题是,如果我是提供此iframe的网站(在这种情况下通过Visa验证),是否有一种方法可以强制现代浏览器不允许我的页面在http://页面上用作iframe ,但仍允许它在https://页面上用作iframe?是否真的应该在这里使用Visa验证的技术?
这是我的 1 个模型的管理页面目前的样子:
我想在按钮旁边添加一个按钮,Add note
这将允许我执行 django 操作。有什么办法可以完成这项工作吗?我只想要按钮扫描笔记并删除空的笔记,但我可以解决这一部分。我只想知道如何在旁边添加一个按钮,Add note
以便将其链接到 django。
感谢您的帮助!
如果浏览器不支持 CSS 伪类(例如 ),会发生什么情况:dir
?
例如:
html:dir(rtl) {
color: red;
}
Run Code Online (Sandbox Code Playgroud)
如果浏览器不理解:dir
伪类,他们会忽略这条规则吗?我对一般情况比对这个特定的伪类更感兴趣。我的直觉告诉我是的,但我还没有找到证实我直觉的文档。
这个问题与这个问题不同:无效的 CSS 选择器导致规则被删除:原理是什么?。它的范围更窄,我问的是浏览器在看到它无法识别的伪类时会做什么,而不是一般情况下它对无效的 CSS 选择器会做什么。据我所知,例如,无法识别的伪类仍可能被视为有效的选择器。
MySQL 似乎使用用户和表等词,而 PostgreSQL 似乎使用用户、模式和关系等词。它们相等吗?有没有关于 MySQL 中哪些单词与 PostgreSQL 匹配的快速指南?
最近,我在update_or_create方法中遇到问题。首先让我给出完整的解释。
模型:
class TransactionPageVisits(models.Model):
transactionid = models.ForeignKey(
Transaction,
on_delete=models.CASCADE,
db_column='transactionid',
)
sessionid = models.CharField(max_length=40, db_index=True)
ip_address = models.CharField(max_length=39, editable=False)
user_agent = models.TextField(null=True, editable=False)
page = models.CharField(max_length=100, null=True, db_index=True)
method = models.CharField(max_length=20, null=True)
url = models.TextField(null=False, editable=False)
created_dtm = models.DateTimeField(auto_now_add=True)
class Meta(object):
ordering = ('created_dtm',)
Run Code Online (Sandbox Code Playgroud)
功能:
def _tracking(self, request, response, **kwargs):
txn_details = kwargs.get('txn_details')
data = {
'sessionid': request.session.session_key,
'ip_address': get_ip_address(request),
'user_agent': get_user_agent(request),
'method': request.method,
'url': request.build_absolute_uri(),
'transactionid': txn_details.txn_object,
'page': kwargs.get('page')
}
# Keep updating/creating tracking data …
Run Code Online (Sandbox Code Playgroud) 使用'Photologue',我可以上传图像作为表单的一部分没问题.但是,在测试计划中,我无法获得要验证的图像.
在tests.py中:
data_photo = {'competition': self.newcomp,
'title': 'Rabbit',
'image': open('photocompetitions/static/img/body_bg.jpg'),
'flickr_id': '425258',
'description': 'A picture of a rabbit',
'location': 'POINT (5000 5000)',
'location_description': 'Just some random place',
'copyright': 'Copyright 2011'}
photoform = PhotoForm(data_photo)
Run Code Online (Sandbox Code Playgroud)
一切正常,但"图像"字段失败,因为"此字段是必需的".消息,所以我假设尽管open()命令没有收到它.'image'字段是photologue的ImageModel模型,并作为标准上传表单显示在网站上.
使用Perl调试器,我知道我可以使用该b
命令在某些代码行设置断点.一旦变量的内容发生变化,我可以让调试器停止吗?
django ×6
python ×4
css ×1
debugging ×1
django-views ×1
forms ×1
https ×1
iframe ×1
image ×1
mysql ×1
perl ×1
postgresql ×1
pseudo-class ×1
python-3.x ×1
security ×1
sql ×1
watch ×1