小编Jam*_*Lin的帖子

当 DEBUG=False 时 django 管道会中断管理

这是css的设置

PIPELINE_CSS = {
    'base': {
        'source_filenames': (
            'scss/core.scss',
        ),
        'output_filename': 'css/min.css',
    },
   'ie8': {
        'source_filenames': (
            'css/ie-8-overrides.css',       
        ),
        'output_filename': 'css/ie8.css',
    },
}
Run Code Online (Sandbox Code Playgroud)

不知怎的,它抱怨:

ValueError: The file 'admin/css/base.css' could not be found with <pipeline.storage.PipelineCachedStorage object at 0x10c34add0>.
Run Code Online (Sandbox Code Playgroud)

django django-pipeline

4
推荐指数
1
解决办法
640
查看次数

为什么python str.format不调用str()

我有以下课程

class A(object):
  def __unicode__(self):
    return u'A'

  def __str__(self):
    return 'AA'

>>> u"{}".format(A())
u'A'
>>> "{}".format(A())
'AA'
>>> str(A())
'AA'
Run Code Online (Sandbox Code Playgroud)

根据文件,

"Harold是一个聪明的{0!s}"##首先在参数上调用str()

为什么这仍然回归你'不'u'AA'?

>>> u"{0!s}".format(A())
u'A'
Run Code Online (Sandbox Code Playgroud)

我希望它和它一样

>>> u"{}".format(str(A()))
u'AA'
Run Code Online (Sandbox Code Playgroud)

python

4
推荐指数
1
解决办法
561
查看次数

Django Rest Framework覆盖了modelserialzer中的模型字段

假设我有这个序列化器:

class DashboardItemSerializer(ModelSerializer):
    offer = serializers.SerializerMethodField()
    cart_item = serializers.SerializerMethodField()
    stock_details = serializers.SerializerMethodField()

    class Meta:
        model = OrderItem
        fields = ('uuid', 'seller', 'total', 'tax', 'offer', 'shipping_address', 'cart_item', 'stock_details')

    def offer(self, obj):
        return 123

    def cart_item(self, obj):
        return 123

    def stock_details(self, obj):
        return 123
Run Code Online (Sandbox Code Playgroud)

这些字段offer,cart_item并且stock_details是模型字段,我想覆盖它以返回不同的值,但看起来像DRF忽略自定义字段并返回obj中的原始值.

如果我不将它们放在fields列表中,则数据将不包括这些字段.

class DashboardItemSerializer(ModelSerializer):
    offer = serializers.SerializerMethodField()
    cart_item = serializers.SerializerMethodField()
    stock_details = serializers.SerializerMethodField()

    class Meta:
        model = OrderItem
        fields = ('uuid', 'seller', 'total', 'tax', 'shipping_address')

    def offer(self, obj):
        return 123 …
Run Code Online (Sandbox Code Playgroud)

django django-rest-framework

4
推荐指数
1
解决办法
5621
查看次数

将客户端IP信息添加到django logger中

我正在尝试将客户端IP添加到日志文件中,我考虑过扩展Logger,但不确定如何访问请求对象并将IP放入记录对象

from logging.handlers import RotatingFileHandler

class RequestRotatingFileLogger(RotatingFileHandler, object):
    def emit(self, record):
        """
        code to manipulate the record to add an attribute to have client IP
        record.ip = '123.123.123.123'
        """
        super(RequestRotatingFileLogger,self).emit(record)
Run Code Online (Sandbox Code Playgroud)

django ip logging

3
推荐指数
1
解决办法
2922
查看次数

django,压缩机和基础scss

嗨我正在尝试使用django-compressor的预编译器将基础scss集成到django中,该项目看起来像这样:

??? manage.py
??? requirements.txt
??? static
?   ??? config.rb
?   ??? humans.txt
?   ??? index.html
?   ??? javascripts
?   ?   ??? foundation
?   ?   ?   ??? foundation.alerts.js
?   ?   ?   ??? foundation.clearing.js
?   ?   ?   ??? foundation.cookie.js
?   ?   ?   ??? foundation.dropdown.js
?   ?   ?   ??? foundation.forms.js
?   ?   ?   ??? foundation.joyride.js
?   ?   ?   ??? foundation.js
?   ?   ?   ??? foundation.magellan.js
?   ?   ?   ??? foundation.orbit.js
?   ?   ?   ??? foundation.placeholder.js
?   ?   ?   ??? foundation.reveal.js
?   ? …
Run Code Online (Sandbox Code Playgroud)

django sass zurb-foundation

3
推荐指数
1
解决办法
2274
查看次数

nginx 允许所有不起作用

我试图允许 pinterest 访问我的开发站点的图像,目前 nginx Deny.conf 正在使用auth_basic和允许 IP 列表。deny all里面没有。satisfy any也在deny.conf中

我添加allow all到站点的配置并重新启动/重新加载 nginx,但仍然被 pinterest 拒绝访问。

location ^~ ^/(cache|media|static)/ {
        allow all;
        access_log off;
        expires 1y;
    }
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

configuration nginx

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

Git 显示文件的最后更改

我用谷歌搜索了这个问题以及很多文章,展示了如何查看过去几天或最后一次提交的更改。

我真正想要的是查看文件的最后更改,无论何时以及哪个提交。

假设我有 FileA 和 FileB

提交 1:更改了 FileA 和 FileB

提交2~99:更改了FileB

我想查看的是对 FileA 的最后一次更改是什么,而不知道哪个提交影响了 FileA。

当我 git pull 共享项目时,这特别有用(至少对我来说),我看到大量提交更改的文件列表,我感兴趣对某些文件进行了哪些更改,但这有点难做。

git diff

3
推荐指数
1
解决办法
1306
查看次数

Django多态模型在1.7上进行迁移时遇到问题

我正在为模型使用Django 1.7和django-polymorphic

class ReferenceItem(PolymorphicModel):
    created_at = models.DateTimeField(_('date created'), auto_now_add=True, db_index=True)
    updated_at = models.DateTimeField(_('date modified'), auto_now=True, db_index=True)
    uuid = UUIDField(auto=True, unique=True)
    description = models.CharField(max_length=255)

class OrderItem(ReferenceItem):
    order = models.ForeignKey('Order', related_name='items')
    sku = models.CharField(max_length=255)
    quantity = models.IntegerField()
    unit_price = models.DecimalField(max_digits=10, decimal_places=2)
    amount = models.DecimalField(max_digits=10, decimal_places=2)
    tax_rate = models.DecimalField(max_digits=3, decimal_places=2)
    commission_rate = models.DecimalField(max_digits=3, decimal_places=2)
Run Code Online (Sandbox Code Playgroud)

当我运行时makemigrations,出现此错误:

raise InvalidBasesError("Cannot resolve bases for %r\nThis can happen if you are inheriting models from an app with migrations (e.g. contrib.auth)\n in an app with no migrations; …
Run Code Online (Sandbox Code Playgroud)

django makemigrations

3
推荐指数
1
解决办法
2915
查看次数

OSX ld:找不到用于-lssl的库

我正在尝试使用python 3在OSX high sierra上的virtrualenv中安装mysqlclient,并得到以下错误:

  Failed building wheel for mysqlclient
  Running setup.py clean for mysqlclient
Failed to build mysqlclient
Installing collected packages: mysqlclient, coverage, django-coverage-plugin, Pygments, babel, alabaster, sphinxcontrib-websupport, imagesize, pyparsing, packaging, snowballstemmer, MarkupSafe, Jinja2, docutils, Sphinx, typing, django-extensions, Werkzeug, django-test-plus, text-unidecode, python-dateutil, Faker, factory-boy, sqlparse, django-debug-toolbar, decorator, simplegeneric, wcwidth, prompt-toolkit, appnope, pickleshare, ptyprocess, pexpect, ipython-genutils, traitlets, parso, jedi, ipython, ipdb, py, pluggy, attrs, pytest, pytest-django, termcolor, pytest-sugar
  Running setup.py install for mysqlclient ... error
    Complete output from command /private/var/virtualenvs/todobackend/bin/python3.6 -u …
Run Code Online (Sandbox Code Playgroud)

mysql macos virtualenv python-3.x

3
推荐指数
1
解决办法
1177
查看次数

Pip 安装和平台特定的轮子

如何pip install选择要安装的轮子?

假设我为不同的平台构建了多个轮子,上传到 PyPI 会pip install <package>自动安装与平台匹配的正确轮子吗?

如果我构建了一个 Linux 特定的轮子并上传到 PyPI,而 Windows/Mac 上的某个人试图通过运行来安装它,会发生pip install <package>什么?

python pip python-wheel

3
推荐指数
1
解决办法
1570
查看次数