ОШИБКА ЕСТЬ -
NoReverseMatch at /updatemedicine/2
Reverse for 'updatemedicine' with keyword arguments '{'pk1': ''}' not found. 1 pattern(s) tried: ['updatemedicine/(?P<pk1>[0-9]+)$']
Request Method: GET
Request URL: http://127.0.0.1:8000/updatemedicine/2
Django Version: 2.2.4
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'updatemedicine' with keyword arguments '{'pk1': ''}' not found. 1 pattern(s) tried: ['updatemedicine/(?P<pk1>[0-9]+)$']
Exception Location: C:\Users\lenovo\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\urls\resolvers.py in _reverse_with_prefix, line 668
Python Executable: C:\Users\lenovo\AppData\Local\Programs\Python\Python37-32\python.exe
Python Version: 3.7.4
Python Path:
['D:\\django project\\admin4',
'C:\\Users\\lenovo\\AppData\\Local\\Programs\\Python\\Python37-32\\python37.zip',
'C:\\Users\\lenovo\\AppData\\Local\\Programs\\Python\\Python37-32\\DLLs',
'C:\\Users\\lenovo\\AppData\\Local\\Programs\\Python\\Python37-32\\lib',
'C:\\Users\\lenovo\\AppData\\Local\\Programs\\Python\\Python37-32',
'C:\\Users\\lenovo\\AppData\\Roaming\\Python\\Python37\\site-packages',
'C:\\Users\\lenovo\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\site-packages',
'C:\\Users\\lenovo\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\site-packages\\win32',
'C:\\Users\\lenovo\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\site-packages\\win32\\lib',
'C:\\Users\\lenovo\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\site-packages\\Pythonwin']
МОЙ HTML КОД ЕСТЬ ===
{% extends 'Pharmacetical/homepage.html' %}
{% block content %}
<div class="box box-warning">
<div class="box-header with-border">
<h3 class="box-title">Add Medicines Here</h3>
</div>
<!-- /.box-header -->
<div class="box-body">
<form role="form" method="POST" action="{% url 'updatemedicine' pk1=med.pk1 %}" enctype="multipart/form-data">
<!-- text input -->
{% csrf_token %}
<div class="form-group">
<label>Disease Name</label>
<select class="form-control" name="desigid">
{% for i in d %}
<option value="{{ med.dsg_id }}">{{ i.diseas }}</option>
{% endfor %}
</select>
</div>
<div class="form-group">
<label>Medicine Name</label>
<textarea class="form-control" rows="3" name="medname" id="" value="{{ med.medicine }}" placeholder="Enter ..."></textarea>
</div>
<div class="form-group">
<label>Uses</label>
<textarea class="form-control" rows="3" name="uses" id="" value="{{ med.uses }}" placeholder="Enter ..."></textarea>
</div>
<div class="form-group">
<label>Side Effects</label>
<textarea class="form-control" rows="3" name="effects" id="" value="{{ med.sideeffects }}" placeholder="Enter ..."></textarea>
</div>
<div class="form-group">
<label>Precautions</label>
<textarea class="form-control" rows="3" name="precaution" id="" value="{{ med.precautions }}" placeholder="Enter ..."></textarea>
</div>
<div class="form-group">
<label>Overdoses</label>
<textarea class="form-control" rows="3" name="over" id="" value="{{ med.overdoses }}" placeholder="Enter ..."></textarea>
</div>
<div class="form-group">
<label>Image</label>
<input type="file" name="pho" value="{{ med.images }}" >
</div>
<!-- textarea -->
<button type="submit" value="Addme" class="btn btn-primary">Submit</button>
</form>
</div>
<!-- /.box-body -->
</div>
{% endblock %}
МОЙ URL ЕСТЬ ===
path("updatemedicine/<int:pk1>",views.updatemedicine,name="updatemedicine"),
Мой код обзора ====
def updatemedicine(request,pk1):
if request.method == "POST":
medi = request.POST['medname']
use = request.POST['uses']
side = request.POST['effects']
precaut = request.POST['precaution']
over = request.POST['over']
s = Medicines.objects.get(id=pk1)
s.dsg = Diseases.objects.get(id=request.POST['desigid'])
s.medicine = medi`enter code here`
s.uses = use
s.sideeffects = side
s.precautions = precaut`enter code here`
s.overdoses = over
s.images = request.FILES['pho']
s.save()
return redirect("/datatablee")
else:
d = Diseases.objects.all()
med = Medicines.objects.get(id=pk1)
return render(request,'Pharmacetical/editmedicine.html',{"d":d,"med":med})
И мой код моделей ===
class Medicines(models.Model):
dsg = models.ForeignKey(Diseases,on_delete=models.CASCADE)
medicine = models.CharField(max_length=200)
uses = models.CharField(max_length=200)
sideeffects = models.CharField(max_length=200)
precautions = models.CharField(max_length=200)
overdoses = models.CharField(max_length=200)
images = models.ImageField(upload_to='medicines/')
Итак, я проверил свою базу данных, данные внутри таблицы одинаковы и принадлежит одному и тому же идентификатору, но каждый раз, когда я пытаюсь его обновить, выдает ошибку, и я не знаю, как ее решить. пожалуйста, помогите мне в этом, и это будет признательно