今天早上,我在Yosemite(10.10.3)的Macbook Pro上遇到了Virtualenv的问题:
$ virtualenv ENV
New python executable in ENV/bin/python2.7
Also creating executable in ENV/bin/python
Installing setuptools, pip, wheel...
Complete output from command /Users/USER/Docu...jp/ENV/bin/python2.7 -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip wheel:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/virtualenv_support/pip-7.0.3-py2.py3-none-any.whl/pip/__init__.py", line 13, in <module>
File "/usr/local/lib/python2.7/site-packages/virtualenv_support/pip-7.0.3-py2.py3-none-any.whl/pip/utils/__init__.py", line 23, in <module>
File "/usr/local/lib/python2.7/site-packages/virtualenv_support/pip-7.0.3-py2.py3-none-any.whl/pip/_vendor/__init__.py", line 72, in load_module
File "/usr/local/lib/python2.7/site-packages/virtualenv_support/pip-7.0.3-py2.py3-none-any.whl/pip/_vendor/pkg_resources/__init__.py", line 967, in <module>
File "/usr/local/lib/python2.7/site-packages/virtualenv_support/pip-7.0.3-py2.py3-none-any.whl/pip/_vendor/pkg_resources/__init__.py", line 970, in Environment
File "/usr/local/lib/python2.7/site-packages/virtualenv_support/pip-7.0.3-py2.py3-none-any.whl/pip/_vendor/pkg_resources/__init__.py", line 260, in …Run Code Online (Sandbox Code Playgroud) 我正在使用付款处理程序Stripe在我的DRF结构中与哲学问题作斗争.我正在Product通过我的DRF REST API 销售具有django模型的产品.我想知道我是否应该创建Product,然后在我的create视图中处理付款如下:
class ProductViewSet(viewsets.ModelViewSet):
...
def create(self, request):
serializer = ProductSerializer(data=request.data)
serializer.is_valid(raise_exception=True)
product = serializer.save()
try:
response = stripe.Charge.create(
amount=product.cost,
currency="usd",
source=request.data["token"], # Done with Stripe.js
description="Product"
)
product.charge_id = response.charge_id
...
Run Code Online (Sandbox Code Playgroud)
或者,如果我应该处理序列化器中的付款Product:
class ProductSerializer(serializers.Serializer):
...
def create(self, validated_data):
product = Product.objects.create(**validated_data)
# Will raise an Excetpion and stop the creation:
response = stripe.Charge.create(
amount=product.cost,
currency="usd",
source=validated_data["token"], # Done with Stripe.js
description="Product"
) …Run Code Online (Sandbox Code Playgroud) 当后端是具有多对多关系的Django-rest-framework(DRF)应用程序时,将pouchdb集成到具有同步功能的Web应用程序中的最佳方法是什么?
例如,假设我有这样的模型:
class Account(models.Model):
name = models.CharField()
class Expense(models.Model):
amount = models.DecimalField()
user = models.ForeignKey(User)
account = models.ForeignKey(Account)
# Multiple users are in the account:
class AccountUser(models.Model):
account = models.ForeignKey(Account)
user = models.ForeignKey(User)
Run Code Online (Sandbox Code Playgroud)
使用足够的序列化程序来计算帐户总数和足够的权限.
我要么需要DRF来表现像Couchdb(带转数),要么将Couchdb与DRF集成(使用Coudhdbkit?还是单独使用?).我怎样才能做到这一点?还有其他方法吗?
谢谢