0

Im trying to create view in which I can save templates as draft and Update the draft if its value is 1 or otherwise save a new document

I have the following Url configuration

url(r'^addprescription/(?P<pid>\d+)/$', views.viewtemplate, name='newtemplate')

for this view

def viewtemplate(request, pid):
    patient = Patient.objects.get(patientid=pid)
    #form = templateform(request.POST)
    if request.method == "POST":
        if presciptiontemplates.draft == 1:
            form = newpatientform(request.POST, instance=patient)
            if form.is_valid():
                form = form.save(commit=False)
                form.patientid = pid
                form.save()
                messages.success(request, 'Form submission successful')
            return redirect('index')
        else:
            form = templateform(request.POST)
            if form.is_valid():
                form = form.save(commit=False)
                form.patientid = pid
                form.save()
            return redirect('index')
    else:
        form = templateform()
    return render(request, 'presapp/prescription.html', {'form': form})`

Template

<a  class="waves-effect waves-light btn right" href="{% url 'newtemplate' pid=patientid%} " >Add new </a>

Im getting the error

Reverse for 'newtemplate' with arguments '()' and keyword arguments '{'pid': ''}' not found. 1 pattern(s) tried: ['addprescription/(?P\d+)/$']

Django 1.10 Python 3.5 Windows 7

  • It looks like `pid` outputs an empty variable in your template. Does the page still give you an error if you use `{% url 'newtemplate' pid=1%}`? – Hybrid Jan 07 '17 at 19:08
  • I tried to use it It only shows data for which there is existing data How Can i change the View accordingly – Romil Bahukhandi Jan 07 '17 at 19:11

0 Answers0