我有两个列表,我想在一个数组中合并,最后把它放在一个csv文件中.我是Python的数组的新手,我不明白我怎么能避免这个错误:
def fill_csv(self, array_urls, array_dates, csv_file_path):
result_array = []
array_length = str(len(array_dates))
# We fill the CSV file
file = open(csv_file_path, "w")
csv_file = csv.writer(file, delimiter=';', lineterminator='\n')
# We merge the two arrays in one
for i in array_length:
result_array[i][0].append(array_urls[i])
result_array[i][1].append(array_dates[i])
i += 1
csv_file.writerows(result_array)
Run Code Online (Sandbox Code Playgroud)
得到了:
File "C:\Users\--\gcscan.py", line 63, in fill_csv
result_array[i][0].append(array_urls[i])
TypeError: list indices must be integers or slices, not str
Run Code Online (Sandbox Code Playgroud)
我的计数如何运作?
我尝试在Ubuntu服务器16.04上的Django + Supervisor + NGINX中部署我的网站.
这是我的.conf(主管):
[program:sitepro]
command = /home/user/sitepro/bin/gunicorn sitepro.wsgi:application --bind mywebsite.fr:8002
user = user
autostart = true
autorestart = true
Run Code Online (Sandbox Code Playgroud)
我的NGINX配置文件:
server {
listen 80;
server_name .mywebsite.fr;
charset utf-8;
root /home/user/sitepro/site/sitepro;
access_log /home/user/sitepro/site/logs/nginx/access.log;
error_log /home/user/sitepro/site/logs/nginx/error.log;
location /static {
alias /home/user/sitepro/site/static;
}
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
proxy_pass http://127.0.0.1:8002;
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试在项目的根目录上启动gunicorn时,一切顺利:
(sitepro) user@mybps:~/sitepro/site$ gunicorn sitepro.wsgi:application --bind mywebsite.fr:8002
[2017-11-01 16:09:37 +0000] [1920] [INFO] Starting gunicorn 19.7.1
[2017-11-01 16:09:37 +0000] [1920] [INFO] Listening at: …
Run Code Online (Sandbox Code Playgroud) 我是Symfony 3的新手.我尝试解决我的两个控制器的问题.当我执行indexAction函数时,我遇到了这个错误:
自动加载器期望类"Arcturus\GeomancieBundle\Controller\TirageController"在文件"/Applications/MAMP/htdocs/geomancie2/geomancie/vendor/composer/../../src/Arcturus/GeomancieBundle/Controller/TirageController中定义. PHP的".找到该文件但该类不在其中,类名或命名空间可能有拼写错误.
我发现这可能是班上的一个错字......但没有发现任何错误.
这是我的两个控制器:
DefaultController.php
<?php
namespace Arcturus\GeomancieBundle\Controller;
namespace Arcturus\GeomancieBundle\Entity;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Form;
use Symfony\Component\HttpFoundation\Request;
use Arcturus\GeomancieBundle\Entity;
class DefaultController extends Controller
{
public function indexAction(Request $request) {
$tirage = new Tirage();
$formTirage = $this->createFormBuilder($tirage)->getForm();
// Si le formulaire a été soumis
$formTirage->handleRequest($request);
if ($formTirage->isSubmitted() && $formTirage->isValid()) {
$tirage = $formTirage->all();
return $this->redirectToRoute('arcturus_geomancie_tirage', $tirage);
}
// Si le formulaire n'a pas été soumis
return $this->render('ArcturusGeomancieBundle:Default:index.html.twig', array(
'form' => $formTirage->createView(),
));
}
}
Run Code Online (Sandbox Code Playgroud)
TirageController.php
<?php
namespace Arcturus\GeomancieBundle\Controller;
namespace Arcturus\GeomancieBundle\Entity; …
Run Code Online (Sandbox Code Playgroud) 我在 Django 1.11 上工作,在我的模板文件中我有这个代码:
{% for article in all_articles %}
{% set color_category = 'light-blue' %}
{% if article.category == 'SEO' %}
{% color_category = 'light-blue' %}
{% elif article.category == 'SEA' %}
{% color_category = 'amber' %}
{% elif article.category == 'Python' %}
{% color_category = 'green' %}
{% elif article.category == 'Django' %}
{% color_category = 'light-green' %}
{% else %}
{% color_category = 'light-blue' %}
{% endif %}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
Django 返回给我这个错误:
Exception Type: TemplateSyntaxError
Exception …
Run Code Online (Sandbox Code Playgroud)