A
A
Andrei Ramanchyk2017-07-20 23:35:23
Django
Andrei Ramanchyk, 2017-07-20 23:35:23

Why when the id becomes two-digit when filling the rows of the table, I get the error keyword arguments '{'pk': 12}' not found?

0dcd0a97769a49569b536316184138f3.JPG
The following error takes off from the moment when the 10th record appears in the table. The table looks something like this
99620e13be97401f8f6b79833029e404.JPG
I'm going from my html page 'executor.html'

<tbody>
    {% for us in users %}
        <tr>
            <th>{{ us.id }}</th>
            <th>
                {% ifequal us request.user %}
                <a href={% url 'projects' pk=us.id name=us.username %}> {{ us.username }}</a>
                {% else %} {{ us.username }}
                {% endifequal %}
            </th>
            <th>{{ us.email }}</th>
        </tr>
    {% endfor %}
    </tbody>

View for this html
class ExecutorView(TemplateView):
    template_name = 'executor.html'
    context_object_name = 'executors'

    def get_context_data(self, **kwargs):
        context = super(ExecutorView, self).get_context_data(**kwargs)
        users = User.objects.all()
        context['users'] = users
        return context

GO to project.html view which
class ProjectsView(DetailView):
    # model = User
    model = ModuleWork
    template_name = 'projects.html'

    def get_context_data(self, **kwargs):
        context = super(ProjectsView, self).get_context_data(**kwargs)
        modules = ModuleWork.objects.filter(executor=self.kwargs['pk']).order_by('-module_work_data')
        context['name'] = self.kwargs['name']
        context['modules'] = modules
        return context

HTML code
{% block table %}
    <div class="scrollable">
        <table>
            <thead>
            <tr>
                <th>#</th>
                <th>Code project</th>
                <th>Type module</th>
                <th>Data</th>
                <th>Engineer</th>
                <th>Description</th>
                <th>Is produced?</th>
            </tr>
            </thead>
            <tbody>
            {% for module in modules %}
                <tr>
                    <th>{{ module.pk }}</th>
                    <th><a href={% url 'project_module' pk=module.id %}>{{ module.project }}-{{ module.room }}{{ module.room_number }}-
                        {{ module.module.module_symbol }}{{ module.module_number }}</a></th>
                    <th>{{ module.module.module_name }}</th>
                    <th>{{ module.module_work_data }}</th>
                    <th>{{ module.executor }}</th>
                    <th>{{ module.project }}</th>
                    <th>{{ module.module_work_is_produced }}</th>
                </tr>
            {% endfor %}
            </tbody>
        </table>

    </div>

{% endblock %}

And when switching from executor to project, it knocks out an error when clicking on the conditional execotora, which includes lines
with id 10 and higher
55c114c1b22541e58f7abfb3f10b0b44.JPG
In the picture above, for example, if I switch to one author, where lines up to 10 everything works, and where lines above 10 - an error.
urls.py
urlpatterns = [
    url(r'^tutorial/', include('django_tutorial.urls')),
    url(r'^projects/photo$', ProjectsPhotoView.as_view(), name='projects_photo'),
    url(r'^login/$', LoginView.as_view(), name='authenticate'),
    url(r'^logout/', LogoutView.as_view(), name="log_aut"),
    url(r'^project_create/$', NewProjectCreate.as_view(), name='new_project'),
    url(r'^create/module/$', permission_required('Module.can_add_new_module')(ModuleCreateView.as_view()),
        name='new_module'),
    url(r'^projectobjectives/create/(?P<pk>\d+)$', TaskItemCreate.as_view(), name='create'),
    url(r'^projectobjectives/delete/(?P<pk>\d+)-(?P<id>\d+)$', TaskItemDelete.as_view(), name='delete'),
    url(r'^projectobjectives/edit/(?P<pk>\d+)-(?P<id>\d+)$', TaskItemEdit.as_view(), name='edit'),
    url(r'^test/$', TemplateView.as_view(template_name='index.html'), name='index'),
    url(r'^module/project_objectives/(?P<pk>\w)/$', ProjectObjectivesView.as_view(), name='project_objectives'),
    url(r'^projects/module/(?P<pk>\d)/photo$', ModulePhotoView.as_view(), name='project_module_photo'),
    url(r'^projects/module/(?P<pk>\d)/$', ModuleView.as_view(), name='project_module'),
    url(r'^basic/module/(?P<pk_old>\w)/(?P<pk>\w)/$', BasicModuleDetailsView.as_view(), name='basic_module_detail'),
    url(r'^basic/module/(?P<pk>\w)/$', BasicModuleView.as_view(), name='basic_module'),
    url(r'^admin/', admin.site.urls),
    url(r'^rooms/(?P<pk>\w+)/$', RoomView.as_view(), name='rooms'),
    url(r'^create/important-features/$', ImportantFeaturesCreate.as_view(), name='important_features_create'),
    url(r'^projects/(?P<name>\w+)-(?P<pk>\d+)/$', ProjectsView.as_view(), name='projects'),
    url(r'^projects/all/$', login_required(ProjectsAllView.as_view()), name='projects_all'),
    url(r'^executor/$', ExecutorView.as_view(), name='executor'),
    url(r'^$', HomeView.as_view(), name='home'),
]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2017-07-20
@jagrmi

url(r'^projects/module/(?P<pk>\d+)/$', 
          ModuleView.as_view(), name='project_module'),

\d- one number
\d+- one or more

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question