Python 找不到如何正确实现django paypal

Python 找不到如何正确实现django paypal,python,django,django-forms,paypal-ipn,django-paypal,Python,Django,Django Forms,Paypal Ipn,Django Paypal,我知道django paypal系统应该如何工作。我尝试按照以下说明操作: 我的问题是我大部分都不懂。这就是我所拥有的: views.py from django.core.urlresolvers import reverse from django.shortcuts import render from paypal.standard.forms import PayPalPaymentsForm from .models import Subs from .forms import Su

我知道django paypal系统应该如何工作。我尝试按照以下说明操作:

我的问题是我大部分都不懂。这就是我所拥有的:

views.py

from django.core.urlresolvers import reverse
from django.shortcuts import render
from paypal.standard.forms import PayPalPaymentsForm
from .models import Subs
from .forms import SubForm
from django.shortcuts import redirect
from forum.views import home
from django.urls import reverse


def BuyShit(request):
    user = request.user
    if request.method == "POST":
        formbuy = SubForm(request.POST)
        if formbuy.is_valid() and 'buy' in request.POST:
            sub = formbuy.save(commit=False)
            sub.owner = user
            sub.save()
            order_created.delay(sub.id)
            request.session['order_id'] = sub.id
            return redirect(home)
forms.py

from django import forms
from .models import Subs

class SubForm(forms.ModelForm):
    class Meta:
        model = Subs

        fields = ('item','price')

models.py

from django.db import models
from forum.models import Post
from django.contrib.auth.models import User
# Create your models here.

class Subs(models.Model):
    item = models.Charfield(max_length=55, verbose_name='item')
    price = models.Charfield(max_length=55, verbose_name='item')
    owner = models.Charfield(User, max_length=55, verbose_name='item')
我还为paypal添加了适当的设置和url:

 url(r'^paypal/', include('paypal.standard.ipn.urls')),
在django paypal的链接上,他们在views.py中有以下内容:

from django.core.urlresolvers import reverse
from django.shortcuts import render
from paypal.standard.forms import PayPalPaymentsForm

def view_that_asks_for_money(request):

    # What you want the button to do.
    paypal_dict = {
        "business": "receiver_email@example.com",
        "amount": "10000000.00",
        "item_name": "name of the item",
        "invoice": "unique-invoice-id",
        "notify_url": request.build_absolute_uri(reverse('paypal-ipn')),
        "return": request.build_absolute_uri(reverse('your-return-view')),
        "cancel_return": request.build_absolute_uri(reverse('your-cancel-view')),
        "custom": "premium_plan",  # Custom command to correlate to some function later (optional)
    }

    # Create the instance.
    form = PayPalPaymentsForm(initial=paypal_dict)
    context = {"form": form}
    return render(request, "payment.html", context)
我应该使用它的哪一部分?我应该在哪里添加它的成本或标题

然后有一个hooks.py的东西我真的不明白它是怎么工作的:

from paypal.standard.models import ST_PP_COMPLETED
from paypal.standard.ipn.signals import valid_ipn_received

def show_me_the_money(sender, **kwargs):
    ipn_obj = sender
    if ipn_obj.payment_status == ST_PP_COMPLETED:
        # WARNING !
        # Check that the receiver email is the same we previously
        # set on the `business` field. (The user could tamper with
        # that fields on the payment form before it goes to PayPal)
        if ipn_obj.receiver_email != "receiver_email@example.com":
            # Not a valid payment
            return

        # ALSO: for the same reason, you need to check the amount
        # received, `custom` etc. are all what you expect or what
        # is allowed.

        # Undertake some action depending upon `ipn_obj`.
        if ipn_obj.custom == "premium_plan":
            price = ...
        else:
            price = ...

        if ipn_obj.mc_gross == price and ipn_obj.mc_currency == 'USD':
            ...
    else:
        #...

valid_ipn_received.connect(show_me_the_money)
所有的部件似乎都断开了。我对django很熟悉,但这似乎完全不同。 我完全迷路了。网上的教程也很糟糕。请帮忙!!!我只需要添加一个按钮来购买单个产品,一旦成功,就会触发一个函数来修改相应的模型。听起来很简单。。。。。谢谢你的帮助