How can I print the url to the order id field of my django form?


I am doing a simple form site with Django. This is what my sites url is looks like:
I want to print the part after the register (12345678) to the order id field. When someone goes this url then i want to print it.
How can i do that? These are my codes.(Currently using Django 1.11.10)

from django import forms
from .models import Customer
from . import views

class CustomerForm(forms.ModelForm):

    class Meta:
        model = Customer
        fields = (

        widgets = {
            'order_id': forms.TextInput(attrs={'class':'orderidcls'}),
            'full_name': forms.TextInput(attrs={'class':'fullnamecls'}),
            'company': forms.TextInput(attrs={'class':'companycls'}),
            'email': forms.TextInput(attrs={'class':'emailcls'}),
            'phone_number': forms.TextInput(attrs={'class':'pncls'}),
            'note': forms.Textarea(attrs={'class':'notecls'}),


from django.shortcuts import render
from olvapp.models import Customer
from olvapp.forms import CustomerForm
from django.views.generic import CreateView,TemplateView

def guaform(request,pk):

    form = CustomerForm()

    if request.method == "POST":
        form = CustomerForm(request.POST)

        if form.is_valid():

            print('ERROR FORM INVALID')

    theurl = request.get_full_path()
    orderid = theurl[10:]

    return render(request,'',{'form':form,'orderid':orderid})


{% extends 'base.html' %}

{% block content %}


<form class="registclass" method="POST">
  {% csrf_token %}
  {{ form.as_p }}

  <button type="submit" class="btn btn-default">REGISTER</button>


{% endblock %}

from django.conf.urls import url
from django.contrib import admin
from olvapp import views

urlpatterns = [



SamSparx is right, here’s some additional information to help prevent such errors in advance:

urlpatterns = [

You are using regex to parse your path. Regex is generally speaking not recommended in this case according to the docs because it might introduce more errors and is harder to debug. (Unoptimized) RegEx also tends to be slower.

For simple use cases such as your path here, consider choosing the default pathing syntax as below:

urlpatterns = [

You could of course also use string instead of int depending on your usage of pk.

Your paths do not all end with a slash consistently. This might impact your SEO and confuse users. See this and this.

Also your form is not imported .as_view() for some reason which could cause some problems.

Answered By – Shellsort

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published