小编Dan*_*ill的帖子

在现有数据库上安装South的问题.MySql不支持'模式更改语句'

我有一个带有现有数据库的django项目,我真的想避免转储或中断.我正在尝试安装South但是当我运行初始迁移时python manage.py migrate example出现以下错误:

Running migrations for example:
- Migrating forwards to 0001_initial.
> example:0001_initial
! Error found during real run of migration! Aborting.

! Since you have a database that does not support running
! schema-altering statements in transactions, we have had 
! to leave it in an interim state between migrations.

! You *might* be able to recover with:   = DROP TABLE `example_page` CASCADE; []
= DROP TABLE `example_likebydate` CASCADE; []
= DROP TABLE `example_followbydate` CASCADE; …
Run Code Online (Sandbox Code Playgroud)

mysql django django-south

4
推荐指数
1
解决办法
2050
查看次数

尝试从视图写入文件时权限被拒绝

我为此问题创建了聊天记录:此处

我有一个尝试执行的视图,f = open('textfile.txt', 'w')但是在我的活动服务器上,这会引发错误[Errno 13] Permission denied: 'textfile.txt'

我的文件结构如下:

- root
    |
    - project
          |
          - app
          |
          - media
Run Code Online (Sandbox Code Playgroud)

视图所在的地方app

我尝试将textfile.txt驻留在根目录,项目,应用程序和媒体中,所有这些文件均具有777文件权限(所有者,组和公共可以读取,写入和执行)[* 1]。

如果我将命令更改为读取权限,即f = open('textfile.txt', 'r')得到相同的错误。

我的媒体根目录设置为,os.path.join(os.path.dirname(__file__), 'media').replace('\\','/') 并且都通过webfaction在apache服务器上运行。

所以我有两个问题。django / python是从哪里打开这个文件的?以及需要更改哪些内容才能获得视图打开和写入文件的权限。

[* 1]我知道这不是一个好主意,我只是将此设置用于当前调试目的。


编辑:

我不知道这是否相关,但是现在当我将其更改为f = open(os.path.join(settings.MEDIA_URL, 'textfile.txt'), 'r')而不是f = open(os.path.join(settings.MEDIA_URL, 'textfile.txt'), 'w')得到错误时[Errno 2] No such file or directory

我不知道这是否有意义...

apache django permissions

4
推荐指数
1
解决办法
9632
查看次数

为什么php字符串中的所有单个单词

所以今天我遇到了这个功能/ bug,我正在努力绕过正在发生的事情.

所以我们都知道在php中:

echo 'hello';
print 'world';
echo gettype('test');
Run Code Online (Sandbox Code Playgroud)

将返回此:

hello
world
string
Run Code Online (Sandbox Code Playgroud)

然而,直到今天我才意识到这一点:

echo hello;
print world;
echo gettype(hello);
Run Code Online (Sandbox Code Playgroud)

将返回此:

hello
world
string
Run Code Online (Sandbox Code Playgroud)

这里发生了什么?在php的编译过程中发生了什么,它将任何单个单词视为字符串?这有名字吗?它有什么用处吗?

php

4
推荐指数
1
解决办法
293
查看次数

github api v3中的oauth流无法正常工作

所以这应该很简单,但我似乎无法找到我的失败点.希望其他人可以向我指出.

首先我去https://github.com/login/oauth/authorize?client_id=CLIENT_ID&scope=gist,这将返回一个代码给我.然后我这样做:

import requests, json

client_id = XXXX
client_secret = XXXX
code = XXXX

r = requests.post(
    'https://github.com/login/oauth/access_token', 
    data=json.dumps({
        'client_id':client_id, 
        'client_secret':client_secret,
        'code':code
    })
r.content  # this gives me a 404 header
Run Code Online (Sandbox Code Playgroud)

当我转到我的测试用户时,它会将我显示为已授权,并且我的应用显示为拥有一个用户,但我没有访问令牌.

我究竟做错了什么.

python api oauth github

4
推荐指数
1
解决办法
1992
查看次数

在临时内存中访问用户上传的视频时出现问题

我正在尝试使用 html 输入类型file和 python 模块 youtube-upload 将用户上传的视频提交到 youtube 。提交表单时,它的处理方式如下:

if request.method == 'POST':
    video = request.FILES['file']

    v=str(video)

    command = 'youtube-upload --email=email@gmail.com --password=password --title=title --description=description --category=Sports ' + v

    r = subprocess.Popen(command,   stdout=subprocess.PIPE)
    v = r.stdout.read()
Run Code Online (Sandbox Code Playgroud)

所以我认为问题是我需要为视频提供更完整的路径。如果是这种情况,访问临时内存中视频的路径是什么。

命令的通用 for 是: youtube-upload --email=email --password=password --title=title --description=description --category=category video.avi

或者,我已经在这里专门查看了 youtube api 但是如果有人可以提供有关如何使用 api 在 python 中执行此操作的更完整的解释,那将是惊人的。不幸的是,网站上的指南只关注 xml。

在 sacabuche 的评论之后编辑:

所以我的观点现在大致是:

def upload_video(request):
     if request.method == 'POST':
         video = request.FILE['file']
         v = video.temporary_file_path
         command = …
Run Code Online (Sandbox Code Playgroud)

python youtube django

3
推荐指数
1
解决办法
2252
查看次数

如何使用变量名,ID,值设置复选框的链接

我有一长串复选框,每个复选框旁边都有一个链接.就像是:

<form name="checkboxlist" action="..." >
    <input type="checkbox" id="1" name="pageCB" value="1"/>
    <a id="1" href="#" onclick="sub(id)>click here</a>
    <input type="checkbox" id="2" name="pageCB" value="2"/>
    <a id="2" href="#" onclick="sub(id)>click here</a>
    ...
    ...
    <input type="submit" />
</form>
Run Code Online (Sandbox Code Playgroud)

我目前正在尝试使用:

<script>
    function sub(id){
        $("input:checkbox[value=id]").attr("checked", true);
        document.checkboxlist.submit(); 
    }
</script>
Run Code Online (Sandbox Code Playgroud)

但是这显然没有读取变量id,我真的想避免为每个id制作if语句,因为它们有几百个.有办法做到这一点吗?

html javascript jquery

0
推荐指数
1
解决办法
3272
查看次数

在Java应用程序中暂停游戏

我正在尝试为游戏添加暂停功能.不幸的是,我目前使用的方法导致程序不再需要输入,所以我无法恢复游戏.

这是我目前正在做的事情:

暂停按钮调用:

public void pause(){
    if(data.paused == true){
        data.paused = false;
    }
    else{
        data.paused=true;
        while(true){
            if(data.paused == true){
                try{
                    Thread.currentThread().sleep(100);
                }
                catch(InterruptedException ie){
                    System.out.println(ie);
                }
            }
            else
                break;
        }
        data.paused=false;
    }
  return;
Run Code Online (Sandbox Code Playgroud)

然后我有一个我必须处理的TimerTask:

class aTask extends java.util.TimerTask {
    protected Data data;
    public aTask( Data d ) { data = d; }
    public void run() { 
        try{ 
            if(data.paused){
                try{
                    Thread.currentThread().sleep(100);
                }
                catch(InterruptedException ie){
                    System.out.println(ie);
                }
            }
            else
                data.tick(); 
        } 
        catch( ATCGameOverException e ){ 
            data.gameOver( e.getMessage() );
        }
    }
};
Run Code Online (Sandbox Code Playgroud)

tick每秒钟在游戏中引起一次动作. …

java

0
推荐指数
1
解决办法
2705
查看次数

PHP闭包需要传递参数

试图找出为什么php匿名函数只有在函数头中给出参数时才有效.

例如

$f = function(){
    echo "hello world";
};
$f;
$f();
Run Code Online (Sandbox Code Playgroud)

不行.但

$f = function($argument){
    echo $argument;
}
$f('hello world');
Run Code Online (Sandbox Code Playgroud)

工作得很好.

为什么它需要参数,是否有任何解决方法?

编辑

这必须是版本问题.我在5.3.18,我的第一个例子肯定不起作用.对于那些不相信的人,它会抛出:

Parse error: syntax error, unexpected T_FUNCTION in index.php(192) : 
  eval()'d code on line 1
Run Code Online (Sandbox Code Playgroud)

编辑

在看了DaveRandom的回答后,我又回到了不知道发生了什么.那就是如果它们是正确的,它在5.3.10中有效......

php closures

0
推荐指数
1
解决办法
141
查看次数

标签 统计

django ×3

php ×2

python ×2

apache ×1

api ×1

closures ×1

django-south ×1

github ×1

html ×1

java ×1

javascript ×1

jquery ×1

mysql ×1

oauth ×1

permissions ×1

youtube ×1