Having the below error while trying to dispatch two variables from my template to my view via url dispatching. I dont understand why the url is not able to be found. This is a snippet of my entire code, but I am pretty sure that the issue lies in the below. This is within an application within my project
NoReverseMatch at /home/patientid=1002411102/clinicid=1007/
Reverse for 'patient_summary' with no arguments not found. 1 pattern(s) tried: ['home/patientid=(?P<patient_id>\\d+)/clinicid=(?P<clinic_id>\\d+)/$']
index.html
<tbody>
{% for patient in patients %}
<tr class="gradeX">
<td>{{patient.PatientID}}</td>
<td>{{patient.ClinicID}}</td>
<td>{{patient.PatientFirstName}}</td>
<td>{{patient.PatientMidName}}</td>
<td>{{patient.PatientLastName}}</td>
<td>{{patient.PatientDOB}}</td>
<td>40/30</td>
<td>192</td>
<td>100</td>
<td>70</td>
<td>23m</td>
<td style="color:red">Abnormal</td>
<td><a style="color:#4A90E2; cursor: pointer" href="{% url 'home:patient_summary' patient_id=patient.PatientID clinic_id=patient.ClinicID %}">View/Edit</a></td>
</tr>
{% endfor %}
</tbody>
urls.py
from django.conf.urls import url
from home import views
app_name = 'home'
urlpatterns = [
url('^$', views.index, name='index'),
url('patientid=(?P<patient_id>\d+)/clinicid=(?P<clinic_id>\d+)/$', views.patient_summary, name='patient_summary'),
]
views.py
from django.shortcuts import render
from django.http import HttpResponse
from django.template.context_processors import request
from django.contrib.auth.decorators import login_required
import requests
import json
@login_required
def index(request):
payload = {"ClinicId":"1007"}
r = requests.post("https://hidden", data=payload)
jsonList = r.text
data = json.loads(jsonList)
# print(data[0]["PatientID"])
patients = []
for patient in data:
patients.append(patient)
my_dict = {'patients': patients, 'homeIsActive': 'active'}
return render(request, 'home/index.html', my_dict)
def patient_summary(request, patient_id, clinic_id):
my_dict = {'homeIsActive': 'active', 'chartData': [[0,1],[1,1],[2,1]]}
return render(request, 'home/patient_summary.html', my_dict)
urls.py for base project
from django.contrib import admin
from django.urls import path
from django.conf.urls import include
from django.conf.urls import url
from login import views as login
from home import views as home
from enrollment import views as enrollment
from inventory import views as inventory
urlpatterns = [
url('^$', login.user_login, name='login'),
url('^logout/', login.user_logout, name='logout'),
url('^home/', include('home.urls')),
url('^enrollment/', enrollment.index, name ='enrollment'),
url('^inventory/', inventory.index, name ='inventory'),
# url('^settings/', settings.index, name='settings'),
url('^settings/', include('settings.urls')),
path('admin/', admin.site.urls),
]
I was calling the url name of patient_summary from another location so thats why I kept getting the error. i think rule of thumb is always use relative url paths
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.