On 24/01/2019 1:08 am, Matthew Pava wrote:
It looks like your second URL is different than the first.
*/admin/substance/substance/1442/change/payment*
*/admin/substance/substance/1442/change/payment/change/*
If you just want to add a slash, then add it.
*/admin/substance/substance/1442/change/payment/*
I’m guessing that Django is interpreting the second URL like so:
*/admin/substance/substance/(pk=1442/change/payment)/change/*
You are right. It looks like Django expects the last element of the url
to be the id and automatically appends 'change' to a modelAdmin url.
That apparently invokes the 'change' form.
My mission (I think) is to find a way to launch a non-Admin url from
inside the Admin. Or perhaps from a model method.
That is what I meant with the word 'breakout' in the subject line.
Derek suggested a modelAdmin wrapper a few days ago ... "Basically you
can create your own view and use that to display data in a template that
inherits from, for example, the Django admin form template. A bit tricky
first time but then it seems straightforward."
I'm finding it a bit tricky for sure!
If you can see a way ...
Thanks
Mike
*From:*django-users@googlegroups.com
[mailto:django-users@googlegroups.com] *On Behalf Of *Mike Dewhirst
*Sent:* Wednesday, January 23, 2019 12:57 AM
*To:* Django users
*Subject:* Admin form_url breakout problem
How can I break out of the Admin to a payment gateway? I've tried
form_url='billing:payment_view' in SubstanceAdmin.change_view()
unsuccessfully.
I can semi-break out of the admin and get the beginning of a payment
happening with the following ...
SubstanceAdmin.change_form_template = payment.html (which has Stripe
js and necessary hidden fields)
or
./templates/admin/substance/substance/change_form.html (identical to
payment.html except it calls block.super at the end to render the rest
of the admin page)
SubstanceAdmin.change_view() which collects the contextual data
required for either template
IngredientsInline.form (inherits admin.StackedInline.form) for all
the hidden fields for each ingredient.
With all that, if an ingredient hasn't been paid for, the
billing.Subscription record won't have a Stripe token so the Admin
will launch the payment page. On entering credit card detail and
pressing the button, Stripe happily takes the money and issues a
token. BUT the Admin then barfs with ...
RuntimeError at /admin/substance/substance/1442/change/payment
You called this URL via POST, but the URL doesn't end in a slash and
you have APPEND_SLASH set. Django can't redirect to the slash URL
while maintaining POST data. Change your form to point to
localhost:8000/admin/substance/substance/1442/change/payment/ (note
the trailing slash), or set APPEND_SLASH=False in your Django settings.
... If I add a slash in the browser address bar and press Enter the
next problem emerges ...
ValueError at /admin/substance/substance/1442/change/payment/change/
invalid literal for int() with base 10: '1442/change/payment'
... which tells me the Admin is hoping for
/admin/substance/substance/1442/
I don't know where to go now.
My preference would be to leave the Admin somehow and handle the
payment externally with my billing.payment_view() and
billing.success_view() then at the end find a way to give that
hoped-for url to the server and expect the substance to come up
normally in the admin.
Any advice will be greatly appreciated. Happy to show any code you
might want to see.
Many thanks
Mike
--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to django-users+unsubscr...@googlegroups.com
<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com
<mailto:django-users@googlegroups.com>.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/f8061a7d-27b5-c929-c364-d8870829ad3e%40dewhirst.com.au
<https://groups.google.com/d/msgid/django-users/f8061a7d-27b5-c929-c364-d8870829ad3e%40dewhirst.com.au?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to django-users+unsubscr...@googlegroups.com
<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com
<mailto:django-users@googlegroups.com>.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/d0ae4053cd254b2bbc982cff3637d0a6%40iss2.ISS.LOCAL
<https://groups.google.com/d/msgid/django-users/d0ae4053cd254b2bbc982cff3637d0a6%40iss2.ISS.LOCAL?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Django
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/1a6d5511-1273-1420-4481-959813a13654%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.