我使用django paypal允许用户在我的网站上付款,但是我有一些疑问。
它目前对我的工作方式是,我有一个名为profile.html的模板。当用户单击“单击更多订阅选项”按钮时,他将被重定向到显示订阅表和贝宝按钮的subscriptions.html模板。单击按钮时,用户将被重定向到另一个名为paypal.html的模板,该模板显示从django- paypal的forms.py派生的另一个paypal按钮
我在这里的问题是如何修改贝宝视图,这样我就可以取消paypal.html,当用户点击subscription.html中的paypal按钮时,直接将用户引导到实际的paypal网站?
我希望我对这个问题的描述足够清楚。
在我的views.py:
def paypal(request):
paypal_dict = {"business":settings.PAYPAL_RECEIVER_EMAIL,"amount": "1.00","item_name": "Milk" ,"invoice": "12345678", "notify_url": "%s%s" % (settings.SITE_NAME, reverse('paypal-ipn')),"return_url": "http://rosebud.mosuma.net",}
# Create the instance.
form = PayPalPaymentsForm(initial=paypal_dict)
context = {"form": form.sandbox()}
return render_to_response("paypal.html", context)在我的profile.html:
....
<INPUT TYPE="submit" Value="Click to find out subscription plans" name="subscription" onClick="/subscribe/>在我的subscription.html:
<form method="post" action="paypal/">
<select name="subscription_input" id="id_subscription" style = "float: center">
<option>Monthly</option>
<option>Yearly</option>
</select></br></br>
{{ form }}
</form>在我的urls.py:
url(r'^paypal/$', 'r2.views.paypal', name='paypal'),
url(r'^profile/paypal/$', 'r2.views.paypal', name='paypal'),发布于 2019-05-18 05:13:32
如果您希望用户一单击PayPal中的PayPal按钮就直接访问subscription.html网站,您将不得不在subscription.html而不是paypal.html中呈现PayPal表单。此外,您需要在PayPalPaymentsForm中子类forms.py,以覆盖默认的PayPal映像"Buy“,因为您希望自己的按钮首先工作。
forms.py
from paypal.standard.forms import PayPalPaymentsForm
from django.utils.html import format_html
class ExtPayPalPaymentsForm(PayPalPaymentsForm):
def render(self):
form_open = u'''<form action="%s" id="PayPalForm" method="post">''' % (self.get_endpoint())
form_close = u'</form>'
# format html as you need
submit_elm = u'''<input type="submit" class="btn btn-success my-custom-class">'''
return format_html(form_open+self.as_p()+submit_elm+form_close)views.py
from .forms import ExtPayPalPaymentsForm
def paypal(request):
paypal_dict = {"business":settings.PAYPAL_RECEIVER_EMAIL,"amount": "1.00","item_name": "Milk" ,"invoice": "12345678", "notify_url": "%s%s" % (settings.SITE_NAME, reverse('paypal-ipn')),"return_url": "http://rosebud.mosuma.net",}
# Create the instance.
form = ExtPayPalPaymentsForm(initial=paypal_dict)
context = {"form": form.sandbox()}
return render_to_response("subscription.html", context)https://stackoverflow.com/questions/9768219
复制相似问题