小编Swi*_*tch的帖子

使用Django和Python创建JSON响应

我正在尝试将服务器端Ajax响应脚本转换为Django HttpResponse,但显然它不起作用.

这是服务器端脚本:

/* RECEIVE VALUE */
$validateValue=$_POST['validateValue'];
$validateId=$_POST['validateId'];
$validateError=$_POST['validateError'];

/* RETURN VALUE */
$arrayToJs = array();
$arrayToJs[0] = $validateId;
$arrayToJs[1] = $validateError;

if($validateValue =="Testuser"){  // Validate??
    $arrayToJs[2] = "true";       // RETURN TRUE
    echo '{"jsonValidateReturn":'.json_encode($arrayToJs).'}';  // RETURN ARRAY WITH success
}
else{
    for($x=0;$x<1000000;$x++){
        if($x == 990000){
            $arrayToJs[2] = "false";
            echo '{"jsonValidateReturn":'.json_encode($arrayToJs).'}';   // RETURNS ARRAY WITH ERROR.
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这是转换后的代码

def validate_user(request):
    if request.method == 'POST':
        vld_value = request.POST.get('validateValue')
        vld_id = request.POST.get('validateId')
        vld_error = request.POST.get('validateError')

        array_to_js = [vld_id, vld_error, False] …
Run Code Online (Sandbox Code Playgroud)

python django json

433
推荐指数
13
解决办法
47万
查看次数

如何在SQL Server中重命名表?

SQL我使用的查询是:

ALTER TABLE oldtable RENAME TO newtable;
Run Code Online (Sandbox Code Playgroud)

但是,它给了我一个错误.

服务器:消息156,级别15,状态1,行1
关键字"TO"附近的语法不正确.

sql-server rename alter-table

361
推荐指数
7
解决办法
46万
查看次数

Python问题:无法找到vcvarsall.bat

可能重复:
错误:无法找到vcvarsall.bat

我正在尝试为python安装MySql接口,但是我收到了一个错误(如下所述).我知道解决方案:安装Microsoft Visual C++.除了安装Microsoft Visual C++之外,还有其他解决方案吗?我的意思是这真的伤害了我; 我为什么要安装Microsoft Visual C++只是因为构建这个单独的包,从开发人员的角度来看,这是一种无用且浪费时间的方法.这个问题还有其他解决方案吗?

MySQL-python-1.2.3c1>setup.py install
running install
running bdist_egg
running egg_info
writing MySQL_python.egg-info\PKG-INFO
writing top-level names to MySQL_python.egg-info\top_level.txt
writing dependency_links to MySQL_python.egg-info\dependency_links.txt
reading manifest file 'MySQL_python.egg-info\SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'MySQL_python.egg-info\SOURCES.txt'
installing library code to build\bdist.win32\egg
running install_lib
running build_py
copying MySQLdb\release.py -> build\lib.win32-2.6\MySQLdb
running build_ext
building '_mysql' extension
error: Unable to find vcvarsall.bat
Run Code Online (Sandbox Code Playgroud)

我在Windows XP上使用Python 2.6.

python mysql

54
推荐指数
4
解决办法
9万
查看次数

如何在Django框架中使用Cassandra

有没有强大的方法将Cassandra后端实现到使用Django Web框架开发的Web应用程序?

django backend cassandra

45
推荐指数
4
解决办法
2万
查看次数

Django模型| 获取特定列

有没有办法过滤并只获取特定的列?

例如,获取列的所有条目first_name.

django

26
推荐指数
2
解决办法
3万
查看次数

Python | mktime溢出错误

我一直在网上搜索,找不到适合这个问题的解决方案

OverflowError: mktime argument out of range
Run Code Online (Sandbox Code Playgroud)

导致此异常的代码

 t = (1956, 3, 2, 0, 0, 0, 0, 0, 0)
 ser = time.mktime(t)
Run Code Online (Sandbox Code Playgroud)

我想知道这个例外的实际原因,有人说日期不是在有效范围内,但它对我没有任何意义,如果有一个范围可能是什么.这取决于我们使用的系统.也想知道这个问题的一个很好的解决方案.

谢谢.

python

18
推荐指数
1
解决办法
1万
查看次数

Python | 使用ctypes访问dll

我正在尝试访问Firefox Web浏览器附带的dll(nss3.dll)中的某些功能.为了处理这个任务,我在Python中使用了ctypes.问题是它在将dll加载到内存时的初始点失败.

这是我必须这样做的代码片段.

>>> from ctypes import *
>>> windll.LoadLibrary("E:\\nss3.dll")
Run Code Online (Sandbox Code Playgroud)

我得到的例外是

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    windll.LoadLibrary("E:\\nss3.dll")
  File "C:\Python26\lib\ctypes\__init__.py", line 431, in LoadLibrary
    return self._dlltype(name)
  File "C:\Python26\lib\ctypes\__init__.py", line 353, in __init__
    self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] The specified module could not be found
Run Code Online (Sandbox Code Playgroud)

我也尝试从Firefox安装路径加载它,假设可能存在依赖关系.

>>> windll.LoadLibrary("F:\\Softwares\\Mozilla Firefox\\nss3.dll")
Run Code Online (Sandbox Code Playgroud)

但是我得到了与上面提到的相同的例外.

谢谢.

python windows dll firefox ctypes

16
推荐指数
3
解决办法
3万
查看次数

Python | 如何创建动态和可扩展的词典

我想创建一个Python字典,它在多维接受中保存值,它应该能够扩展,这是应该存储值的结构: -

userdata = {'data':[{'username':'Ronny Leech','age':'22','country':'Siberia'},{'username':'Cronulla James','age':'34','country':'USA'}]}
Run Code Online (Sandbox Code Playgroud)

让我们说我想添加另一个用户

def user_list():
     users = []
     for i in xrange(5, 0, -1):
       lonlatuser.append(('username','%s %s' % firstn, lastn))
       lonlatuser.append(('age',age))
       lonlatuser.append(('country',country))
     return dict(user)
Run Code Online (Sandbox Code Playgroud)

这将只返回一个包含单个值的字典(因为键名是相同的值将被覆盖).那么如何将一组值附加到此字典中.

注意:假设age,firstn,lastn和country是动态生成的.

谢谢.

python

11
推荐指数
3
解决办法
5万
查看次数

如何将会话超时设置为大于30分钟

任何人都知道如何设置超过30分钟的会话超时?这两种方法不起作用(默认为30分钟).

<session-config>
<session-timeout>60</session-timeout>
</session-config>
Run Code Online (Sandbox Code Playgroud)

session.setMaxInactiveInterval(600); 
Run Code Online (Sandbox Code Playgroud)

谢谢.

jsp servlets

10
推荐指数
3
解决办法
9万
查看次数

Gradle | 不会排除Spring启动依赖项

我正在尝试让log4j在我正在进行的项目中工作.我在build.gradle中添加了相关的log4j依赖项,并排除了Spring启动启动日志记录,以便它可以工作.

当我使用Maven作为构建工具时,这工作正常,但是一旦我切换到Gradle,它根本不工作(除了从Spring启动器启动记录).以下是build.gradle中的依赖项

dependencies {
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-web'){
        exclude module: 'org.springframework.boot:spring-boot-starter-logging'
    }
    compile('org.springframework.boot:spring-boot-starter-log4j')
    compile('org.springframework.boot:spring-boot-starter-data-rest')
    compile('org.springframework.boot:spring-boot-starter-actuator')
    compile('org.postgresql:postgresql:9.3-1101-jdbc41')
    compile('org.scala-lang:scala-library:2.10.4')
    testCompile('org.springframework.boot:spring-boot-starter-test') {
        exclude module: 'commons-logging'
    }
    providedCompile('org.springframework.boot:spring-boot-starter-tomcat')
}
Run Code Online (Sandbox Code Playgroud)

但是你可以在依赖树中清楚地看到spring-boot-starter-logging它仍然存在.我猜这就是为什么日志记录不起作用的问题.

这是依赖树:

+--- org.springframework.boot:spring-boot-starter-data-jpa: -> 1.2.1.RELEASE
|    +--- org.springframework.boot:spring-boot-starter:1.2.1.RELEASE
|    |    +--- org.springframework.boot:spring-boot:1.2.1.RELEASE
|    |    |    +--- org.springframework:spring-core:4.1.4.RELEASE
|    |    |    \--- org.springframework:spring-context:4.1.4.RELEASE
|    |    |         +--- org.springframework:spring-aop:4.1.4.RELEASE
|    |    |         |    +--- aopalliance:aopalliance:1.0
|    |    |         |    +--- org.springframework:spring-beans:4.1.4.RELEASE
|    |    |         |    |    \--- org.springframework:spring-core:4.1.4.RELEASE
|    |    |         |    \--- org.springframework:spring-core:4.1.4.RELEASE
|    | …
Run Code Online (Sandbox Code Playgroud)

spring log4j gradle build.gradle spring-boot

9
推荐指数
1
解决办法
1万
查看次数