小编mar*_*ark的帖子

付款方式令牌在Braintree中无效

我想在订阅支付网关Braintree的功能方面对其进行测试-对于使用Django(python)的应用程序。

您的代码我只有一个py文件。(无前端)。当我想创建订阅时,出现错误:

<ErrorResult 'Payment method token is invalid.' at 7f101d301390>
Run Code Online (Sandbox Code Playgroud)

如何获得代币支付方式?

这是我所有的代码:

import braintree

braintree.Configuration.configure(braintree.Environment.Sandbox,
                                  merchant_id="myMechrantId",
                                  public_key="myPublicKey",
                                  private_key="myPrivateKey")

client_token = braintree.ClientToken.generate()

client = braintree.Customer.create({
    "first_name": 'Mike',
    "last_name": "Smith",
    "company": "Braintree",
    "email": "jen@example.com",
    "phone": "312.555.1234",
    "fax": "614.555.5678",
    "website": "www.example.com"
})

result = braintree.Subscription.create({
    "payment_method_token": "the_token",
    "plan_id": "Here is my plan ID"
})
Run Code Online (Sandbox Code Playgroud)

python token payment-gateway braintree

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

如何从django中的模型中获取一个字段

我的django应用程序中有这样的模型.我想只绘制这个模型的一个字段并将它们放在视图中.我的解决方案不起作用:

obj = Text.objects.get(subsID)
Run Code Online (Sandbox Code Playgroud)

我的模特

result = braintree.Subscription.create({
        "payment_method_token": payment_method_token,
        "plan_id": "67mm"
        })

subscription_id = result.subscription.id

class Text(models.Model):
    title = models.CharField(max_length=255)
    text = models.TextField()
    date_from = models.DateTimeField('date from', blank=True, null=True)
    date_to = models.DateTimeField('date to', blank=True, null=True)
    subsID = models.CharField(default=subscription_id, max_length=255)

    def __unicode__(self):
        return self.title
Run Code Online (Sandbox Code Playgroud)

我的看法

def get_history(request):
    subscription_id = Text.objects.filter(subsID)
    history = braintree.Subscription.find(subscription_id)
    return render(request, "sheet/history.html", {"history": history})
Run Code Online (Sandbox Code Playgroud)

python django field model

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

在Django中翻译文件时使用Git命令

我在Django中有一个现有的应用程序.我想在页面上添加翻译.在页面上我有:

{% trans 'Projects'%}
Run Code Online (Sandbox Code Playgroud)

在.po文件中我添加了:

#: templates/staff/site.html: 200
msgid "Projects"
msgid "Projekty"
Run Code Online (Sandbox Code Playgroud)

然后执行命令:

django-admin.py compilemessages -l pl
Run Code Online (Sandbox Code Playgroud)

执行此命令后,出现错误:

CommandError: This Should Be Run script from the Django Git checkout or your project or app tree, or with the settings Specified module.
Run Code Online (Sandbox Code Playgroud)

python django translation

4
推荐指数
2
解决办法
2842
查看次数

项目文件夹django 1.8中的TemplateDoesNotExist

我已经构建了我的应用程序Django(Django 1.8),如下所示.当我在app1中尝试模板或app2在我的应用程序的base.html中扩展base.html时,我收到此错误.

TemplateDoesNotExist at /
base.html
Error during template rendering

In template /myProject/project_folder/app1/templates/app1/base.html, error at line 1
{% extends "base.html" %}
Run Code Online (Sandbox Code Playgroud)

这是我的项目的结构

/projekt_folder
    template
        base.html
    /app1
        /template
            base.html <-- {% extends "base.html" %}
    /app2
        /template
            base.html <-- {% extends "base.html" %}
Run Code Online (Sandbox Code Playgroud)

python django django-templates django-views django-1.8

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

django中排除两类用户

我在 django 中有一个应用程序,并且希望在我看来排除匿名用户和管理员用户(那些拥有标志超级用户的用户)。

我已经有排除匿名用户的代码,但是如何将管理员用户放在此处?

我的模型

class MyModel(models.Model):
    user = models.ForeignKey(User, blank=True, null=True)
    name = models.CharField(max_length=255, blank=True, null=True)
Run Code Online (Sandbox Code Playgroud)

这是我的查询:

def get_queryset(self):
    return User.objects.all().exclude(id=settings.ANONYMOUS_USER_ID)
Run Code Online (Sandbox Code Playgroud)

python django

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

Django 中的自定义用户测试

我有一个 Django 应用程序和自定义用户 - 想要测试它(进行单元测试)。我的自定义用户是 emailuser,它由电子邮件和密码字段组成。我想设置一些这样的国家mplayer,给它一个字段和一个密码。但是我下面的代码不起作用。

设置.py

AUTH_USER_MODEL = 'custom_user.EmailUser'
Run Code Online (Sandbox Code Playgroud)

我在 test.py 中的代码

from django.test import TestCase
from django.conf import settings

class MyTest(TestCase):
    def setUp(self):
        self.user = settings.AUTH_USER_MODEL.objects.create('testuser@test.pl', 'testpass')

    def test_user(self):
        self.assertEqual(self.user, 'testuser@test.pl')
Run Code Online (Sandbox Code Playgroud)

python django unit-testing django-custom-user

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