我本质上是一个PHP编码器,开始用Python编写代码.我对Python PDB感到惊讶,有些东西相当于PHP吗?
我正在使用PHP Web框架,我特别想pdb.set_trace()在我们使用Python中的Web框架时非常有用.
我的问题是,有一些与PHP相同的东西?
我已经完成了我的第一个Django/Python项目,现在我需要将这些东西放在真正的生产网络服务器中.
我通过互联网阅读了一些论文,我倾向于选择Ngix,Gunicorn和Git,但我发现的文档不是很完整,如果这是最好的选择,我有很多doubs.
你怎么看待这个主题?我需要一种简单的方法来将我的Django项目放在网上,但网站仍然非常多,我需要在未来的时间内在生产服务器中多次更改代码.
请给我一些关于我应该做些什么的线索.我有点失落......
最好的祝福,
我有一个像这样的PHP数组:
array( [0] => 1
[1] => 2
[2] => 3
[3] => Some strings
)
Run Code Online (Sandbox Code Playgroud)
如何从数组中删除不是整数的条目?我需要输出这个:
array( [0] => 1
[1] => 2
[2] => 3
)
Run Code Online (Sandbox Code Playgroud)
有人能给我一个线索吗?
我需要将UUID作为主键实现,但我不确定如何在Django中执行它.
我的代码
class LinkRenewAd(models.Model): # This model will generate the uuid for the ad renew link
def make_uuid(self):
return str(uuid.uuid1().int>>64)
uuid = models.CharField(max_length=36, primary_key=True, default=make_uuid, editable=False)
main = models.ForeignKey(Main)
expiration_date = models.DateTimeField()
date_inserted = models.DateTimeField(auto_now_add=True)
date_last_update = models.DateTimeField(auto_now=True)
Run Code Online (Sandbox Code Playgroud)
当我尝试在南方生成这个新模型时,我得到了错误:
TypeError: make_uuid() takes exactly 1 argument (0 given)
Run Code Online (Sandbox Code Playgroud) 我没有得到如何使用PHPUnit对异常进行单元测试.
请参阅我的方法与异常:
public function getPhone($html, $tag = 'OFF', $indicative, $number_lenght) {
// .. code
if ($tag <> 'OFF') {
$html = $doc[$tag]->text(); // Apanho apenas o texto dentro da TAG
if (empty($html)) {
throw new Exception("Nao foi possivel apanhar qualquer texto dentro da TAG, Metodo em causa: getPhone()");
}
}
// .. code
}
Run Code Online (Sandbox Code Playgroud)
现在我的PHPUnit测试:
<?php
require_once '../Scrap.php';
class ScrapTest extends PHPUnit_Framework_TestCase
{
protected $scrap;
// Setup function to instantiate de object to $this->scrap
protected function setUp()
{
$this->scrap = …Run Code Online (Sandbox Code Playgroud) 我需要删除多级数组上的空条目.现在我可以删除带有空子数组的条目,但不能删除空数组...混淆,所以我...我认为代码将有助于更好地解释...
<?php
/**
*
* This function remove empty entries on arrays
* @param array $array
*/
function removeEmptysFromArray($array) {
$filtered = array_filter($array, 'removeEmptyItems');
return $filtered;
}
/**
*
* This is a Callback function to use in array_filter()
* @param array $item
*/
function removeEmptyItems($item) {
if (is_array($item)) {
return array_filter($item, 'removeEmptyItems');
}
if (!empty($item)) {
return true;
}
}
$raw = array(
'firstname' => 'Foo',
'lastname' => 'Bar',
'nickname' => '',
'birthdate' => array(
'day' => '',
'month' …Run Code Online (Sandbox Code Playgroud) 我正在Django设计一个模型,但我不知道这是不是最好的方法.我有一个名为"历史"的模型,在这个模型中,我有一个专门的函数来处理这个模型的插入.
备选方案1
class History(models.Model):
field1 = models.ForeignKey(Request)
field2 = models.BooleanField()
field3 = models.DateTimeField()
def __unicode__(self):
return str(self.field1.id)
class Meta: #
ordering = ['-field3']
def insert_history(self):
# Here I will have some business logic to insert the data to the history model
Run Code Online (Sandbox Code Playgroud)
要将数据插入到History模型中,我总是必须使用"insert_history"函数.
我的问题是:
上面的代码是正确的吗?
如果是,我如何从视图中调用"insert_history"?
备选方案2
我有另一种替代方案,我已经测试过并且有效,但感觉不对.代码如下所示:
class History(models.Model):
field1 = models.ForeignKey(Request)
field2 = models.BooleanField()
field3 = models.DateTimeField()
def __unicode__(self):
return str(self.field1.id)
class Meta: #
ordering = ['-field3']
def insert_history(field1, field2, field3):
# Here I will have some business logic …Run Code Online (Sandbox Code Playgroud) 我需要将CodeIgniter设置为真正的多语言网站.我搜索过,但找不到解决方案.
我已经测试了这种方法,但它无法正常工作.(http://codeigniter.com/wiki/Category%3AInternationalization%3A%3AInternationalization_Views_i18n /)
有人能给我一些线索,了解在CodeIgniter中使用什么设置来获得真正的多语言环境?
最好的祝福,
我需要"连接到for循环中的字符串".为了解释,我有这个清单:
list = ['first', 'second', 'other']
Run Code Online (Sandbox Code Playgroud)
在for循环中我需要以此结束:
endstring = 'firstsecondother'
Run Code Online (Sandbox Code Playgroud)
你能告诉我如何在python中实现这个目标吗?
我有一些用PHP编写的代码,但我也开发了一个用Python编写的脚本.是否可以从PHP代码中调用此Python脚本?
如果是,我如何从PHP传递参数到Python脚本?
我试图找到一个没有任何成功的答案.
有人能给我一个线索吗?
php ×5
python ×4
django ×3
arrays ×2
array-filter ×1
codeigniter ×1
debugging ×1
deployment ×1
for-loop ×1
multilingual ×1
phpunit ×1
uuid ×1