小编Cea*_*sta的帖子

ContentType匹配查询不存在

我最近尝试将一些灯具加载到我的数据库中.当我运行服务器并加载各种页面虽然我收到错误:

Caught DoesNotExist while rendering: ContentType matching query does not exist.
Run Code Online (Sandbox Code Playgroud)

我已经尝试运行syncdb,并单独重置每个应用程序,但没有任何运气.如何使此错误消失?

django content-type

8
推荐指数
1
解决办法
1万
查看次数

如何通过Facebook的Graph API获取共同朋友

无论如何使用Facebook的Graph API获取共同朋友的列表?

我一直在玩这个工具,还没有想出办法.然而,我在Facebook的网站上看到了Simon的演示,听起来他能够得到他朋友的共同喜欢(看起来他是怎么做的太模糊了所以)所以我觉得我应该能够,但除了一些PHP脚本,我找不到任何文档.

facebook facebook-graph-api

7
推荐指数
1
解决办法
2万
查看次数

Python MixIn标准

所以我正在编写一些代码,并且最近遇到了实现一些mixin的需要.我的问题是,设计混合的正确方法是什么?我将使用下面的示例代码来说明我的确切查询.

class Projectile(Movable, Rotatable, Bounded):
    '''A projectile.'''
    def __init__(self, bounds, position=(0, 0), heading=0.0):
        Movable.__init__(self)
        Rotatable.__init__(self, heading)
        Bounded.__init__(self, bounds)
        self.position = Vector(position)

    def update(self, dt=1.0):
        '''Update the state of the object.'''
        scalar = self.velocity
        heading = math.radians(self.heading)
        direction = Vector([math.sin(heading), math.cos(heading)])
        self.position += scalar * dt * direction
        Bounded.update(self)

class Bounded(object):
    '''A mix-in for bounded objects.'''
    def __init__(self, bounds):
        self.bounds = bounds

    def update(self):
        if not self.bounds.contains(self.rect):
            while self.rect.top > self.bounds.top:
                self.rect.centery += 1
            while self.rect.bottom < self.bounds.bottom:
                self.rect.centery += 1 …
Run Code Online (Sandbox Code Playgroud)

python design-patterns mixins

7
推荐指数
1
解决办法
1318
查看次数

如何动态更改选择的选择框?

我正在使用Google Maps API创建可选择的社区列表,并使用Chosen使其看起来不错.我遇到的问题是Maps API没有立即获取数据 - 它通过回调函数来实现,这意味着Chosen在添加选项之前应用自身,因此选项无法运行通过选择(导致它们根本不显示).

我认为理论上,如果我可以在选择Chosen之前获取select中的元素,它应该可以工作,但我不确定如何完全这样做.有什么想法吗?

forms jquery

7
推荐指数
1
解决办法
2万
查看次数

Sphinx:类警告:"警告:找不到py:类引用目标"

我有两个文件,foo.pybar.py.

foo.py 包含:

import bar


class B():
    a = bar.A
Run Code Online (Sandbox Code Playgroud)

bar.py 包含:

class A():
    pass
Run Code Online (Sandbox Code Playgroud)

我正在docs/index.rst通过以下方式生成这些文档:

.. automodule:: bar
   :members:
   :undoc-members:

.. automodule:: foo
   :members:
   :undoc-members:
Run Code Online (Sandbox Code Playgroud)

现在,当我build html使用nit-picky flag(-n)运行时,我得到以下内容,并发出警告WARNING: py:class reference target not found: A:

(env)bash-3.2$ make html
sphinx-build -b html -d _build/doctrees  -n . _build/html
Running Sphinx v1.2.3
loading pickled environment... done
building [html]: targets for 1 source files that are out of date
updating environment: 0 …
Run Code Online (Sandbox Code Playgroud)

python python-sphinx

7
推荐指数
1
解决办法
1105
查看次数

如何从Jenkins将Python应用程序部署到Amazon Elastic Beanstalk?

我试图从Jenkins作业以编程方式部署到Amazon Elastic Beanstalk.在我的开发机器上,这很简单:

eb deploy $(AWS_ELASTIC_BEANSTALK_ENVIRONMENT)
Run Code Online (Sandbox Code Playgroud)

在Jenkins上,它应该像将以下配置为构建命令一样简单:

virtualenv env && source env/bin/activate && pip install awsebcli
mkdir -p .elasticbeanstalk
cat << EOF > .elasticbeanstalk/config.yml 
branch-defaults:
  master:
    environment:  myenv
global:
  application_name:  myapp
  default_ec2_keyname: null
  default_platform: 64bit Amazon Linux 2014.09 v1.0.9 running Python 2.7
  default_region: us-west-2
  profile: eb-cli
  sc: git
EOF
eb deploy myenv
Run Code Online (Sandbox Code Playgroud)

但是,这会失败,并带有以下跟踪:

[EnvInject] - Loading node environment variables.
Building remotely on standard Amazon Linux 2014.09 AMI (i-d39710df) (x) in workspace /media/ephemeral0/jenkins/workspace/My_Job
Fetching changes from the remote Git repository
Fetching …
Run Code Online (Sandbox Code Playgroud)

python amazon-web-services jenkins amazon-elastic-beanstalk

7
推荐指数
2
解决办法
4483
查看次数

Bundler 使用错误的 Ruby 版本

当我尝试启动 Rails 服务器时,出现以下错误:

$ bundle exec rails s
Your Ruby version is 2.3.7, but your Gemfile specified ~> 2.3.8
Run Code Online (Sandbox Code Playgroud)

我不明白为什么会发生这种情况,因为我使用 Homebrew 和 rbenv 将 Ruby 设置为 2.3.8。2.3.7是系统的ruby版本。我使用的是 Mac 操作系统 10.14.4。

$ ruby -v
ruby 2.3.8p459 (2018-10-18 revision 65136) [x86_64-darwin18]

$ rbenv version
2.3.8 (set by /Users/ceasar/foo/.ruby-version)

$ which -a ruby
/Users/ceasar/.rbenv/shims/ruby
/usr/local/opt/ruby@2.3/bin/ruby
/usr/local/bin/ruby
/usr/bin/ruby

$ which -a bundle
/Users/ceasar/.rbenv/shims/bundle
/usr/local/bin/bundle

$ /usr/bin/xcodebuild -version
Xcode 10.2
Build version 10E125

$ brew list ruby@2.3
/usr/local/Cellar/ruby@2.3/2.3.8_1/bin/erb
/usr/local/Cellar/ruby@2.3/2.3.8_1/bin/gem
/usr/local/Cellar/ruby@2.3/2.3.8_1/bin/irb
/usr/local/Cellar/ruby@2.3/2.3.8_1/bin/rake
/usr/local/Cellar/ruby@2.3/2.3.8_1/bin/rdoc
/usr/local/Cellar/ruby@2.3/2.3.8_1/bin/ri
/usr/local/Cellar/ruby@2.3/2.3.8_1/bin/ruby
/usr/local/Cellar/ruby@2.3/2.3.8_1/include/ruby-2.3.0/ …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails bundler rbenv

7
推荐指数
1
解决办法
6112
查看次数

如何测试记忆功能?

我有一个简单的memoizer,我用来节省昂贵的网络电话的时间.粗略地说,我的代码看起来像这样:

# mem.py
import functools
import time


def memoize(fn):
    """
    Decorate a function so that it results are cached in memory.

    >>> import random
    >>> random.seed(0)
    >>> f = lambda x: random.randint(0, 10)
    >>> [f(1) for _ in range(10)]
    [9, 8, 4, 2, 5, 4, 8, 3, 5, 6]
    >>> [f(2) for _ in range(10)]
    [9, 5, 3, 8, 6, 2, 10, 10, 8, 9]
    >>> g = memoize(f)
    >>> [g(1) for _ in range(10)]
    [3, 3, 3, 3, 3, …
Run Code Online (Sandbox Code Playgroud)

python unit-testing python-decorators

6
推荐指数
1
解决办法
1829
查看次数

找不到vcvarsall.bat文件

我正在尝试使用pip在我的计算机上安装Scrapy.在大多数情况下它可以工作,但在安装后不久我得到一个错误,说"无法找到vcvarsall.bat.我已经四处寻求帮助,大多数消息来源说安装Visual Express 2008.但是,甚至执行此操作后,当我导航到C:\ Program Files(x86)\ Microsoft Visual Studio 8\VC时,我没有看到vcvarsall.bat文件.有什么想法吗?

python visual-studio-2008

5
推荐指数
1
解决办法
1万
查看次数

如何使用Python创建具有属性的元组?

我有一个WeightedArc类定义如下:

class Arc(tuple):

  @property
  def tail(self):
    return self[0]

  @property
  def head(self):
    return self[1]

  @property
  def inverted(self):
    return Arc((self.head, self.tail))

  def __eq__(self, other):
    return self.head == other.head and self.tail == other.tail

class WeightedArc(Arc):
  def __new__(cls, arc, weight):
    self.weight = weight
    return super(Arc, cls).__new__(arc)
Run Code Online (Sandbox Code Playgroud)

这段代码显然不起作用,因为self没有定义WeightArc.__new__.如何将属性权重分配给WeightArc类?

python inheritance tuples

5
推荐指数
1
解决办法
2049
查看次数