我正在开发自己的博客Django.但是我已经开始坚持了.所以,这是我的树层次结构:
/pyroot/nemoden/
|~blog/
| |-__init__.py
| |-admin.py
| |-models.py
| |-tests.py
| `-views.py
|+css/
|+images/
|+js/
|~templates/
| |-index.html
| `-postslist.html
|-__init__.py
|-manage.py
|-settings.py
`-urls.py
Run Code Online (Sandbox Code Playgroud)
我所做的是:创建一个名为blog的新应用程序并描述我在博客中所需的所有模型blog/models.py(用户,帖子,评论等),但后来我观看Jeff Hui's 视频并意识到这可能是一个坏主意并且在Django-world人们中做那个......我们做什么... PHP-world用我们的PHP Frameworks.我想最好为标签,评论,用户等设置杰出的Django应用程序......
所以,我要问的是:
每个Django-app有一个模型更好吗?如果是这样,当我不应该为模型创建新的Django-app时会有一些例外吗?
我想跟:
/pyroot/nemoden/
|~blog/ # this is actual application (not a django-application). It uses all the models in views.py, so django-apps becomes just models
| |-__init__.py
| |-tests.py
| `-views.py # all the views (controllers in other frameworks) …Run Code Online (Sandbox Code Playgroud) 我想知道如何知道某个特定位置是否用于处理请求nginx.
例如:
# 1
location / {}
# 2
location ~ /[\w\-]+\.html {}
# 3
location ~ /\w+\.html {}
Run Code Online (Sandbox Code Playgroud)
我如何知道URI /mysite是否由第三位而不是第二位处理?我倾向于使用add_header这个问题:
location / {
add_header location 1;
}
location ~ /(\w+\-)\.html {
add_header location 2;
}
location @named {
add_header location named;
}
Run Code Online (Sandbox Code Playgroud)
我想知道有更好的解决方案,或者您个人用于调试目的是什么?
我有以下Django型号代码:
status = models.PositiveIntegerField(default = 0b000)
comments_allowed = models.BooleanField(default = True) # whether comments are allowed to this post
Run Code Online (Sandbox Code Playgroud)
但我预计,它会生成SQL之类的
`status` integer NOT NULL default '4',
`comments_allowed` bool NOT NULL default TRUE
Run Code Online (Sandbox Code Playgroud)
哪个没有发生,当我运行manage.py sqlall appname它时产生:
`status` integer UNSIGNED NOT NULL,
`comments_allowed` bool NOT NULL
Run Code Online (Sandbox Code Playgroud)
深入研究Django代码和谷歌搜索没有给我什么,但詹姆斯班纳特的评论default不会影响生成SQL,但Django管理员需要.即便如此,我如何获得理想的效果?
我的Django版本是1.3.0决赛
我上课了:
class Tag(Base, TimestampMixin):
"""Tags"""
__tablename__ = 'tags'
__table_args__ = {'mysql_engine' : 'InnoDB', 'mysql_charset' : 'utf8' }
id = Column(Integer(11), autoincrement = True, primary_key = True)
tag = Column(String(32), nullable = False, unique = True)
cnt = Column(Integer(11), index = True, nullable = False, default = 1)
def __init__(self, tag):
t = session.query(Tag).filter_by(tag=tag).first()
if t:
self.cnt = t.cnt+1
self.tag = t.tag
else:
self.tag = tag
def __repr__(self):
return "<Tag('%s')>" % (self.tag, )
def __unicode__(self):
return "%s" % (self.tag, )
Run Code Online (Sandbox Code Playgroud)
添加标签时: …
我使用jquery expose插件和Masked Input插件遇到了问题.问题是它们都占据$.mask导致冲突的功能.但我非常需要这两个插件一起工作.我会$.mask在其中一个中重命名...让我们说,$.msk但是在这种情况下我总是需要记住它,如果我想升级到新版本,我会再次重命名.
寻找更好的解决方案,以解决jquery插件之间的这种冲突.
我得到UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-51: ordinal not in range(128)异常尝试使用string.maketrans在Python.我对以下代码(gist)中的这种错误感到气馁:
# -*- coding: utf-8 -*-
import string
def translit1(string):
""" This function works just fine """
capital_letters = {
u'?': u'A',
u'?': u'B',
u'?': u'V',
u'?': u'G',
u'?': u'D',
u'?': u'E',
u'?': u'E',
u'?': u'Zh',
u'?': u'Z',
u'?': u'I',
u'?': u'Y',
u'?': u'K',
u'?': u'L',
u'?': u'M',
u'?': u'N',
u'?': u'O',
u'?': u'P',
u'?': u'R',
u'?': u'S',
u'?': u'T', …Run Code Online (Sandbox Code Playgroud) 在FTP服务器上有一些文件.对于此服务器上的任何小时,都要上传新文件.我想下载最后一个文件.如何从此服务器获取上次上传的文件?所有文件都有不同的名称.
我使用下面的脚本下载一个文件.
$conn = ftp_connect("ftp.testftp.com") or die("Could not connect");
ftp_login($conn,"user","pass");
ftp_get($conn,"target.txt","source.txt",FTP_ASCII);
ftp_close($conn);
Run Code Online (Sandbox Code Playgroud)
提前致谢 !!!
使用example.php:
$args = __FILE__.' -vvv';
$argv = explode(' ', $args);
$argc = count($argv);
$GLOBALS['argv'] = $_SERVER['argv'] = $argv;
$GLOBALS['argc'] = $_SERVER['argc'] = $argc;
var_export(getopt('v'));
Run Code Online (Sandbox Code Playgroud)
$ example.php -v
> array('v'=> false);
最终getopt不羡慕$GLOBALS得到argv.那么我有什么方法可以覆盖argv数组?
我的JavaScript代码几乎不是一个Ajax请求,它要求从后端返回XML.后端可以execute_callback作为XML标签之一返回,如下所示:
<?xml version="1.0" encoding="windows-1251"?>
<response>
<execute_callback>
<function_name>someFunction</function_name>
</execute_callback>
</response>
Run Code Online (Sandbox Code Playgroud)
只要你知道这个callback预期的参数数量,一切都会好的.但如果后端已经返回怎么办?
<?xml version="1.0" encoding="windows-1251"?>
<response>
<execute_callback>
<function_name>someFunction</function_name>
<param>10.2</param>
<param>some_text</param>
</execute_callback>
<execute_callback>
<function_name>otherFunction</function_name>
<param>{ x: 1, y: 2 }</param>
</execute_callback>
</response>
Run Code Online (Sandbox Code Playgroud)
我现在如何将参数10.2和'some_text'传递给someFunctionJSON {x:1,y:2} otherFunction?
我知道一个丑陋的解决方案(使用函数arguments),但我正在寻找一个漂亮的解决方案.
在我忘记之前:不要为我解析XML - 我可以自己解决这个问题:)我需要的只是一些技巧,可以将任意数量的参数传递给JavaScript中的函数.如果您了解Python,我想要:
def somefunc(x, y):
print x, y
args = { 'x' : 1, 'y' : 2 }
somefunc(**args)
Run Code Online (Sandbox Code Playgroud)
但在JavaScript中.
django ×2
php ×2
python ×2
aptana ×1
debugging ×1
declarative ×1
ftp ×1
javascript ×1
jquery ×1
mysql ×1
namespaces ×1
netbeans ×1
nginx ×1
orm ×1
sqlalchemy ×1