我有点好奇知道为什么Django 1.9用设置,URL和其他配置文件中的lists []替换了元组()
我刚升级到Django 1.9并发现了这些变化.他们背后的逻辑是什么?
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles'
]
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]
Run Code Online (Sandbox Code Playgroud)
urls.py
urlpatterns = [
url(r'^', admin.site.urls),
]
Run Code Online (Sandbox Code Playgroud)
这些变化有什么不同吗?
我使用reCaptcha v2但在Uncaught (in promise) null任何情况下都在开发控制台响应(并移动.reset()函数)
安慰:
我的recaptcha代码:
<div class="text-xs-center" style="text-align: center; height:150px;">
<p style="color: black;"> Complete the verification: </p>
<div style="display: inline-block;" class="g-recaptcha" data-sitekey="xxxxxxxxxxx" data-callback="callback"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
我的回调函数:
function callback() {
if (grecaptcha === undefined) {
alert('Recaptcha non definito');
return;
}
var response = grecaptcha.getResponse();
console.log(response);
if (!response) {
alert('Coud not get recaptcha response');
return;
}
$.ajax({
'url' : 'validate-recaptcha.php',
'type' : 'POST',
'data' : {
'response' : response
},
'success' : function(data) {
alert('Data: '+data);
}, …Run Code Online (Sandbox Code Playgroud) 我正在使用多表继承,并想知道如何从超类的实例创建一个继承的类型.
使用文档中给出的示例:
class Place(models.Model):
name = models.CharField(max_length=50)
address = models.CharField(max_length=80)
class Restaurant(Place):
serves_hot_dogs = models.BooleanField()
serves_pizza = models.BooleanField()
Run Code Online (Sandbox Code Playgroud)
现在当你创建一个Restaurant,你自动创建一个Place,这很好,以及我期望和想要的行为.
但是,如果我做了一个Place,后来决定我要转换为特定类型(如Restaurant).你如何Restaurant使用现有的创建Place?
我希望在循环中检测到的每个问题都会出现警告,但警告只会在第一次提出一次.例如 :
import warnings
for i in range(10):
print i
warnings.warn('this is a warning message')
Run Code Online (Sandbox Code Playgroud)
我预计 :
0
UserWarning: this is a warning message
1
UserWarning: this is a warning message
2
UserWarning: this is a warning message
3
UserWarning: this is a warning message
4
Run Code Online (Sandbox Code Playgroud)
但结果是:
0
__main__:4: UserWarning: this is a warning message
1
2
3
4
Run Code Online (Sandbox Code Playgroud)
为什么我只有一个警告?如何获得每次迭代的警告?
在Django(1.9)中尝试.py动态加载文件(模块)(通过importlib).动态重新加载就像魅力一样,但每次重新加载模块时,开发服务器都会重新启动,不得不重新加载其他所有内容.
我正在提取大量外部数据(xml)以进行测试,每次环境重新启动时,都必须重新加载所有这些外部xml数据.我希望能够仅重新加载模块,并保持已加载的xml数据完整,这样每次更改某些py代码时都不必经过该过程.
是否有一个标志我可以设置/切换(或任何其他方法)以防止服务器重新启动此单个模块重新加载的整个过程?
任何帮助非常感谢.
我需要一个没有主键的表(在Django中它是自动创建的).所以我的问题是:我可以创建一个没有ID /主键的模型吗?
我正在使用Django 1.7.
我想用之前的变量(对于所有连续的无)替换Nonein list。我用if和for(多行)做到了。有没有办法在一行中做到这一点?即,列表理解、Lambda 和/或地图
我的想法是使用列表理解,但我无法在列表理解中分配变量来设置以前的值。
我的项目中有一个类似的场景以None这种方式处理,问题是我不想为小功能编写 10 行代码。
def none_replace(ls):
ret = []
prev_val = None
for i in ls:
if i:
prev_val = i
ret.append(i)
else:
ret.append(prev_val)
return ret
print('Replaced None List:', none_replace([None, None, 1, 2, None, None, 3, 4, None, 5, None, None]))
Run Code Online (Sandbox Code Playgroud)
输出:
Replaced None List: [None, None, 1, 2, 2, 2, 3, 4, 4, 5, 5, 5]
我昨天在我的服务器上安装了python 3.6.3(ubuntu 14.04),现在我无法运行python 2.7(在虚拟envs和'main env'上).
我一直在寻找谷歌,没有成功.
当我变红时,我试图重新安装openssl.
谁能帮我 ?我疯了.
--->每当我试图执行python脚本(或pip)时,这是消息:
*ERROR:root:code for hash md5 was not found.
Traceback (most recent call last):
File "/usr/local/lib/python2.7/hashlib.py", line 147, in <module>
globals()[__func_name] = __get_hash(__func_name)
File "/usr/local/lib/python2.7/hashlib.py", line 97, in __get_builtin_constructor
raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type md5
ERROR:root:code for hash sha1 was not found.
Traceback (most recent call last):
File "/usr/local/lib/python2.7/hashlib.py", line 147, in <module>
globals()[__func_name] = __get_hash(__func_name)
File "/usr/local/lib/python2.7/hashlib.py", line 97, in __get_builtin_constructor
raise ValueError('unsupported hash type …Run Code Online (Sandbox Code Playgroud) 我已成功使用以下代码从多个 PDF 页面中提取图像,但分辨率相当低。有办法调整吗?
import fitz
pdffile = "C:\\Users\\me\\Desktop\\myfile.pdf"
doc = fitz.open(pdffile)
for page_index in range(doc.pageCount):
page = doc.loadPage(page_index)
pix = page.getPixmap()
output = "image_page_" + str(page_index) + ".jpg"
pix.writePNG(output)
Run Code Online (Sandbox Code Playgroud)
我还尝试使用此处的代码并将 if pix.n < 5" 更新为 "if pix.n - pix.alpha < 4 但这在我的情况下没有输出任何图像。
感谢您首先阅读本文.
我正在尝试安装Django.这就是我在命令行中所做的事情:
C:\>python34 pip install Django
Run Code Online (Sandbox Code Playgroud)
而这就是我得到的:
C:\Python34\python.exe: can't open file 'pip': [Errno 2] No such file or directory
Run Code Online (Sandbox Code Playgroud)
如果我从site-packages目录执行相同的操作:
C:\Python34\Lib\site-packages>python34 pip install Django
Traceback (most recent call last):
File "C:\Python34\lib\runpy.py", line 170, in _run_module_as_main
"__main__", mod_spec)
File "C:\Python34\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "pip\__main__.py", line 2, in <module>
from .runner import run
SystemError: Parent module '' not loaded, cannot perform relative import
Run Code Online (Sandbox Code Playgroud)
我之前使用过pip,它工作正常,但现在我不知道如何正确运行它...我试图先找到答案,但我不明白其中任何一个.可能是因为我对这一切都比较新.任何人都可以用一年级语言解释我需要做些什么才能做到这一点?
python ×8
django ×5
python-3.x ×3
model ×2
python-2.7 ×2
ajax ×1
django-1.9 ×1
html ×1
inheritance ×1
install ×1
javascript ×1
loops ×1
md5 ×1
orm ×1
pdf ×1
php ×1
pip ×1
pymupdf ×1
recaptcha ×1
warnings ×1