Phillip
Phillip

Reputation: 335

Reverse for 'form_detail' not found. 'form_detail' is not a valid view function or pattern name

I'm trying to redirect to another view that goes to a randomly generated URL but Django can't doesn't know what to render.

I'm not sure what is wrong with my URL's in this one. I think I did it correct, but Django disagrees. What am I doing wrong?

Reverse for 'form_detail' not found. 'form_detail' is not a valid view function or pattern name.

Views.py

def index(request):
    randomUrl = str(uuid.uuid4())
    return redirect("form_detail", random_url=randomUrl)


def form_detail(request, random_url):
    template = "faq.html"
    context = {}
    form_detail = random_url
    context["form_detail"] = form_detail
    stripeUID = str(uuid.uuid4())
    payment = stripe.checkout.Session.create(
  success_url="https://myUrl.com/accepted",
  cancel_url="https://myUrl.com/cancel",
  payment_method_types=["card"],
  client_reference_id= stripeUID,
  line_items=[
    {
      "amount": 2000242,
      "quantity": 1,
      "name": "Expensive item",
      "currency": "usd",
    }
  ]
)   
    context = payment.id
    return render(request, template, context)

App urls.py

from . import views
app_name = 'request'

urlpatterns = [
    path('', views.index, name='index'),
    path('form-detail/(?P<random_url>[-\w]+)/$', views.form_detail, name="form_detail")
]

Upvotes: 0

Views: 740

Answers (1)

CHEMSEDDINE HAROUIT
CHEMSEDDINE HAROUIT

Reputation: 352

I can see that you're inside an app.urls not in the principal project.urls Which means you need to provide a namespace for the app.urls let's call it 'request' So you need to use 'request:form_detail'

Upvotes: 2

Related Questions