我正试图开始使用Sphinx并且似乎有无情的问题.
命令: docs/sphinx-quickstart
我回答所有问题,一切正常.
命令: docs/ls
一切看起来都很正常.结果:build Makefile source
命令: sphinx-build -d build/doctrees source build/html
它似乎工作.我能够打开index.html文件,看到我想要的"shell".
当我尝试将我的实际源代码作为source文件夹时遇到问题.
命令: sphinx-build -d build/doctrees ../ys_utils build/html
结果:
Making output directory...
Running Sphinx v1.1.3
loading pickled environment... not yet created
No builder selected, using default: html
loading intersphinx inventory from http://docs.python.org/objects.inv...
building [html]: targets for 1 source files that are out of date
updating environment: 1 added, 0 changed, 0 removed
Traceback (most recent call last):
File "/usr/local/lib/python2.6/dist-packages/Sphinx-1.1.3-py2.6.egg/sphinx/ext/autodoc.py", line 321, in …Run Code Online (Sandbox Code Playgroud) 我正在尝试为多个SSH帐户创建一个.ssh/config文件(特别是对于github.com).我已经尝试了几个教程和github帮助演练,但似乎没有任何工作.
我创造了一个id_rsa_test和id_rsa_test.pub.我上传id_rsa_test.pub到github.
然后我创建了一个~/.ssh/config包含以下内容的文件:
# github account
Host github.com-test github.com
Hostname github.com
User git
IdentifyFile ~/.ssh/id_rsa_test
Run Code Online (Sandbox Code Playgroud)
和
# github account
Host github.com-test github.com
Hostname github.com
User git
IdentifyFile ~/.ssh/id_rsa_test.pub
Run Code Online (Sandbox Code Playgroud)
然后我尝试几个命令.即:
git clone git@github-test:username/my_project.git
git push
Run Code Online (Sandbox Code Playgroud)
...每次我收到以下错误:
/home/username/.ssh/config: line 5: Bad configuration option: IdentifyFile
/home/username/.ssh/config: terminating, 1 bad configuration options
fatal: The remote end hung up unexpectedly
Run Code Online (Sandbox Code Playgroud)
有什么建议?
如何从Pypi中删除包裹?
几个月前我上传了一个包给Pypi.包裹现在已经过时了,我想正式删除它.我找不到有关如何删除我的包的任何文档.
我使用Python 3使用virtualenvwrapper创建了一个虚拟环境.
mkvirtualenv foo -p /usr/bin/python3
Run Code Online (Sandbox Code Playgroud)
我试图pip安装psycopg2并得到以下错误:
./psycopg/psycopg.h:30:20: fatal error: Python.h: No such file or directory
Run Code Online (Sandbox Code Playgroud)
我有最新版本的python-dev.我可以psycopg2使用Python 2 成功安装virtualenv.
使用Python 3在virtualenv中安装它的诀窍是什么?
我正在使用一个 rc 文件,其中包含:
ignore-patterns=".*local.*"
我希望这会忽略local名称中包含该单词的所有文件。所以tmplocal.py,,,,,,等等。tmp.local.pytmp_local.pylocal_tmp.py
运行 Pylint (1.7.2) 时,不会忽略这些文件。有什么建议么?
我们对大多数项目使用基于类的视图.当我们尝试创建一个CSV Mixin时,我们遇到了一个问题,它允许用户将来自几乎任何页面的信息导出为CSV文件.我们的特殊问题涉及CSV文件,但我相信我的问题是通用的,足以与任何文件类型相关.
我们遇到的问题是视图的响应是试图转到模板(比如说from django.views.generic import TemplateView).我们在urls.py文件中指定模板.
url(r'^$', MyClassBasedView.as_view(template_name='my_template.html'))
Run Code Online (Sandbox Code Playgroud)
如何强制响应绕过模板并返回标准HttpResponse?我猜你需要覆盖一个方法,但我不确定是哪一个.
有什么建议?
编辑1:看来我不清楚我们要做什么.我已经渲染了一个页面(通过基于类的视图),用户将看到信息报告.我需要输入一个"导出到CSV"按钮供用户按,它将在页面上导出信息并将CSV下载到他们的机器上.
不能将视图重写为基于方法的视图.我们处理几乎所有基于类的视图类型(DetailView,ListView,TemplateView,View,RedirectView等)
我有两个 Python 包,其中一个需要由另一个导入。目录结构如下:
workspace/
management/
__init__.py
handle_management.py
other_management.py
utils/
__init__.py
utils_dict.py
Run Code Online (Sandbox Code Playgroud)
我正在尝试从文件utils中的项目导入功能handle_management.py:
import utils.utils_dict
Run Code Online (Sandbox Code Playgroud)
我在尝试运行时遇到错误handle_management.py:
ImportError: No module named utils.utils_dict
Run Code Online (Sandbox Code Playgroud)
我已经阅读了很多有关如何解决此问题的文章,但似乎找不到有效的解决方案。
我从从相对路径导入模块开始- 我尝试了适用的解决方案,但没有一个有效。
是唯一可以workspace/通过 提供的解决方案site_packages吗?如果是这样,最好的方法是什么?
编辑:
我尝试将 - 添加/home/rico/workspace/到PYTHONPATH- 没有运气。
编辑2:
我能够成功使用 klobucar 的解决方案,但我认为它不会作为通用解决方案,因为该实用程序将被其他几个开发人员使用。我知道我可以使用一些 Python 泛化来确定每个用户的相对路径。我只是觉得有一个更优雅的解决方案。
最终,该脚本将通过 cron 运行,对多个 Python 项目执行单元测试。每个开发人员都可以使用它,以确保在开发过程中进行集成测试。
我需要能够使这个更加普遍。
编辑3:
抱歉,对于我想要实现的目标,我真的不喜欢这些解决方案。我很欣赏您的意见 - 我正在使用它们作为临时解决方案。作为一个完整的修复,我将考虑添加一个site_packages目录中可用的脚本,该脚本将添加到PYTHONPATH. 这是多台机器和多个开发人员都需要的。
一旦我构建了完整的解决方案,我将在此处发布我所做的事情并将其标记为解决方案。
编辑4:
我觉得我这个问题好像没有很好地表达我的需求。下面的答案很好地解决了这个问题 - 但不是我的实际需求。因此,我在另一篇文章中重组了我的问题。我考虑编辑这个,但是下面的答案(这对其他人非常有帮助)对更改没有意义,并且看起来不合适且无关紧要。
对于这个问题的修订版本,请参阅Unable to import Python package universally
我在Ubuntu 13.10和Postgres上使用Django 1.6和Python 3.3.
我的模型User定义如下:
from django.db import models
from django.contrib.auth.models import AbstractUser
from common.mixins import TimestampMixin
class User(TimestampMixin, AbstractUser):
auth_key = models.CharField(max_length=16)
def __str__(self):
if self.first_name:
if self.last_name:
return "{0} {1}'s Profile".format(
self.first_name, self.last_name)
else:
return "{0}'s Profile".format(self.first_name)
else:
return "{0}'s Profile".format(self.username)
Run Code Online (Sandbox Code Playgroud)
我测试__str __如下:
from django.test import TestCase
from accounts.models import User
from common.tests.fixtureless import create_instance
class UserTest(TestCase):
def test_str(self):
initial = {
'username': 'test_username',
'first_name': 'test_first_name',
'last_name': 'test_last_name',
}
user = create_instance(User, **initial)
user.save() …Run Code Online (Sandbox Code Playgroud) 我需要能够确定 Django 运行时使用的数据库类型。
MYSQL = False
if <something goes here>:
MYSQL = True
Run Code Online (Sandbox Code Playgroud)
我看到了相关的 Django 票证,但并没有完全找到我的解决方案。(https://code.djangoproject.com/ticket/18332)
如果有一个解决方案,我可以确定它是否是 MySQL、PostgreSQL、SQLite、Oracle...等等,那就太好了。
我尝试过挖掘django.db,但看不到任何有帮助的东西。
我将详细说明我正在尝试做的事情,因为它似乎被误解了。这是一个独立于任何 Django 项目的测试实用程序项目。我的实用程序需要了解正在使用哪个数据库来防止非法活动。
例如,我的包支持 PostgreSQL hstore 字段,但在 SQLite 中不存在这样的字段。因此,如果他们使用 SQLite,我不想允许特定功能。
我可以访问他们与该实用程序一起使用的 Django 模型。
from my_app.models import Foo
testing_utility(Foo, **kwargs)
Run Code Online (Sandbox Code Playgroud)
我的testing_utility签名是:
def testing_utility(klass, **kwargs):
instance = klass(**kwargs)
Run Code Online (Sandbox Code Playgroud)
hstore现在,如果不是 PostgreSQL 数据库,我不想在此类上执行特定功能。这是否更清楚一些?
编辑1:
谢谢 KevinDTimm 提供的链接。看起来 Django 模型._state.db在实例化时确实有。当然,我的实例有一个None类型。:(
>> print(instance._state.db)
None
Run Code Online (Sandbox Code Playgroud) 我获得了一个.pem文件,用于在XML POST API上进行身份验证。我更喜欢使用Python请求,并在文档中找到了将.pem文件转换为服务器认证和密钥所需的文档。我一直无法确切找到请求所需要的(什么样的认证)。
以前我必须对文件进行一些opensl转换,但是我不是专家。谁能解释请求中需要哪种证书和密钥,以及如何将.pem转换为这些文件?
有关请求文档的更多背景信息,请参见http://docs.python-requests.org/en/latest/user/advanced/#ssl-cert-verification
您会注意到对/path/server.crt和的引用/path/key。
python ×6
django ×3
certificate ×1
config ×1
download ×1
github ×1
openssl ×1
orm ×1
psycopg2 ×1
pylint ×1
pypi ×1
python-3.3 ×1
regex ×1
ssh ×1
unit-testing ×1
virtualenv ×1