Я стою с этой ошибкой, я не могу получить "id" из моего списка, я получаю ошибку. я пытаюсь создать кнопку ОБНОВИТЬ для редактирования данных, которые я добавляю в свою базу данных.
Вот мои views.py в моих приложениях
from django.shortcuts import render, redirect
from gomo_web_system.forms import UserForm,NewMasterForm
from django.contrib.auth import authenticate, login, logout
from django.http import HttpResponseRedirect, HttpResponse
from django.urls import reverse
from django.contrib.auth.decorators import login_required
from gomo_web_system.models import masterList
from django.contrib import messages
def index(request):
if request.method == 'POST':
username = request.POST.get('username')
password = request.POST.get('password')
user = authenticate(username=username, password=password)
if user is not None:
login(request, user)
return render(request, 'gomo_web_system/main_menu.html')
else:
messages.info(request, 'Username or Password is incorrect')
context = {}
return render(request, 'gomo_web_system/index.html', context)
def user_logout(request):
logout(request)
return HttpResponseRedirect(reverse('index'))
@login_required
def main_menu(request):
return render(request, 'gomo_web_system/main_menu.html')
@login_required
def it_home(request):
return render(request, 'gomo_web_system/IT/it_home.html')
@login_required
def it_master_list(request):
master_list = masterList.objects.order_by('projectName')
master_dict = {'master':master_list}
return render(request, 'gomo_web_system/IT/it_master_list.html', context=master_dict)
@login_required
def it_create_master_list(request):
form = NewMasterForm()
if request.method == 'POST':
#print('printring POST:', request.POST)
form = NewMasterForm(request.POST)
if form.is_valid():
form.save()
return redirect('gomotion:master_list')
context = {'form':form}
return render(request, 'gomo_web_system/IT/it_add_master_list.html', context)
def it_update_master_list(request, id):
form = NewMasterForm()
context = {'form':form}
return render(request, 'gomo_web_system/IT/it_add_master_list.html', context)
Вот мои в моих приложениях myapp / urls .py
from django.conf.urls import url
from gomo_web_system import views
app_name = 'gomotion'
urlpatterns = [
url('main/',views.main_menu, name="main"),
url('itHome/',views.it_home, name="home"),
url('itMasterList/', views.it_master_list, name="master_list"),
url('itAddMasterList/',views.it_create_master_list, name="add_master_list"),
url('itUpdateMasterList/<int:id>/',views.it_update_master_list, name="update_master_list"),
]
Вот мои в моих приложениях urls.py
from django.contrib import admin
from django.urls import path, include
from gomo_web_system import views
urlpatterns = [
path('', views.index, name='index'),
path('logout/', views.user_logout, name='logout'),
path('gomoadmin/', admin.site.urls),
path('gomotion/', include('gomo_web_system.urls')),
]
этот файл получает ошибку .id в "master_list.id" жирный текст
{% extends 'gomo_web_system/IT/it_base.html' %}
{% load static %}
{% block it_base %}
<!-- Card section -->
<!-- Title row -->
<div class="col-md-9 col-lg-10 py-5">
<div class="row mb-5">
<div class="col text-center">
<h3><span class="text-uppercase text-danger ">MASTER LIST</span></h3>
</div>
</div>
<a href="{% url 'gomotion:add_master_list' %}" class="btn btn-danger btn-block text-uppercase mb-2">Add Project</a>
<table id="master_list_table" class="table table-hover table-bordered">
<!-- table Head -->
<thead class="thead-dark">
<tr>
<th scope="col" class-"text-muted">MASTER</th>
<th scope="col" class-"text-muted">PROJECTS</th>
<th scope="col" class-"text-muted">YEAR</th>
<th scope="col" class-"text-muted">SERIAL</th>
<th scope="col" class-"text-muted">FORMAT</th>
<th scope="col" class-"text-muted">SPACE</th>
<th scope="col" class-"text-muted">BYTES</th>
<th scope="col" class-"text-muted">ACTIONS</th>
</tr>
</thead>
<!-- table body -->
<tbody>
{% for master_list in master %}
<tr>
<td class="text-uppercase">{{ master_list.masterName }}</td>
<td class="text-uppercase"><a href="#">{{ master_list.projectName }}</a></td>
<td class="text-uppercase">{{ master_list.year }}</td>
<td class="text-uppercase">{{ master_list.serialNumber }}</td>
<td class="text-uppercase">{{ master_list.hdFormat }}</td>
<td class="text-uppercase">{{ master_list.space }}</td>
<td class="text-uppercase">{{ master_list.hdBytes }}</td>
**<td><a class="btn btn-sm btn-info" href="{% url 'gomotion:update_master_list' master_list.id %}">update</a></td>**
</tr>
{% endfor %}
</tbody>
</table>
<!-- End of colum -->
</div>
<!-- end of table -->
{% endblock %}
Вот ошибка, которую я получил. 