前提・実現したいこと
Djangoで同一プロジェクト内に複数のアプリケーションを配置し、一覧ページ(http://localhost:8000/vulnerability/week/)から編集機能を実装し、編集ページ(http://localhost:8000/vulnerability/week/mod/1/)にリダイレクトさせる際に、NoReverseMatchのエラーが発生しました。
mybookプロジェクト内にcmsアプリケーションとvulnerabilityアプリケーションを作成しております。今回のエラーはvulnerabilityアプリケーションにおいて発生したものになります。cmsアプリケーションにおいても、同様のビジネスロジックで実装しておりますが、このようなエラーは発生しておりません。
私個人では能力不足により、/mybook/vulnerability/views.pyに起因する問題なのか、/mybook/cms/templates/vulnerability/base.htmlに起因する問題なのか、判断が付かない状態です。回答者の方には、問題の切り分けを行っていただき、エラーメッセージを解決し、正常な動作に戻していただきたいです。
その他必要な情報は全て提供致します。分かりにくい文章で申し訳ありませんが、どうぞよろしくお願い致します。
発生している問題・エラーメッセージ
NoReverseMatch at /vulnerability/week/mod/1/ Error during template rendering In template ~/project/mybook/cms/templates/vulnerability/base.html, error at line 7 7 <link rel="stylesheet" href="{% static 'cms/css/bootstrap.min.css' %}">
該当のソースコード
(vulnerability/views.py) from django.shortcuts import render, get_object_or_404, redirect from vulnerability.models import Week from vulnerability.forms import WeekForm def week_list(request): weeks = Week.objects.all().order_by('id') return render(request,'vulnerability/week_list.html', {'weeks': weeks}) def week_edit(request, week_id=None): if week_id: week = get_object_or_404(Week, pk=week_id) else: week = Week() if request.method == 'POST': form = WeekForm(request.POST, instance=week) if form.is_valid(): week = form.save(commit=False) week.save() return redirect('vulnerability:week_list') else: form = WeekForm(instance=week) return render(request, 'vulnerability/week_edit.html', dict(form=form, week_id=week_id)) def week_del(request, week_id): week = get_object_or_404(Week, pk=week_id) week.delete() return redirect('vulnerability:week_list')
(vulnerability/urls.py) from django.urls import path from vulnerability import views app_name = 'vulnerability' urlpatterns = [ path('week/', views.week_list, name='week_list'), path('week/add/', views.week_edit, name='week_add'), path('week/mod/<int:week_id>/', views.week_edit, name='week_mod'), path('week/del/<int:week_id>/', views.week_del, name='week_del'), ]
$ tree . ├── cms │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-36.pyc │ │ ├── admin.cpython-36.pyc │ │ ├── forms.cpython-36.pyc │ │ ├── models.cpython-36.pyc │ │ ├── urls.cpython-36.pyc │ │ └── views.cpython-36.pyc │ ├── admin.py │ ├── apps.py │ ├── forms.py │ ├── migrations │ │ ├── 0001_initial.py │ │ ├── __init__.py │ │ └── __pycache__ │ │ ├── 0001_initial.cpython-36.pyc │ │ └── __init__.cpython-36.pyc │ ├── models.py │ ├── static │ │ ├── cms │ │ │ ├── css │ │ │ │ ├── bootstrap-grid.css │ │ │ │ ├── bootstrap-grid.css.map │ │ │ │ ├── bootstrap-grid.min.css │ │ │ │ ├── bootstrap-grid.min.css.map │ │ │ │ ├── bootstrap-reboot.css │ │ │ │ ├── bootstrap-reboot.css.map │ │ │ │ ├── bootstrap-reboot.min.css │ │ │ │ ├── bootstrap-reboot.min.css.map │ │ │ │ ├── bootstrap.css │ │ │ │ ├── bootstrap.css.map │ │ │ │ ├── bootstrap.min.css │ │ │ │ └── bootstrap.min.css.map │ │ │ └── js │ │ │ ├── bootstrap.bundle.js │ │ │ ├── bootstrap.bundle.js.map │ │ │ ├── bootstrap.bundle.min.js │ │ │ ├── bootstrap.bundle.min.js.map │ │ │ ├── bootstrap.js │ │ │ ├── bootstrap.js.map │ │ │ ├── bootstrap.min.js │ │ │ └── bootstrap.min.js.map │ │ └── vulnerability │ │ ├── css │ │ │ ├── bootstrap-grid.css │ │ │ ├── bootstrap-grid.css.map │ │ │ ├── bootstrap-grid.min.css │ │ │ ├── bootstrap-grid.min.css.map │ │ │ ├── bootstrap-reboot.css │ │ │ ├── bootstrap-reboot.css.map │ │ │ ├── bootstrap-reboot.min.css │ │ │ ├── bootstrap-reboot.min.css.map │ │ │ ├── bootstrap.css │ │ │ ├── bootstrap.css.map │ │ │ ├── bootstrap.min.css │ │ │ └── bootstrap.min.css.map │ │ └── js │ │ ├── bootstrap.bundle.js │ │ ├── bootstrap.bundle.js.map │ │ ├── bootstrap.bundle.min.js │ │ ├── bootstrap.bundle.min.js.map │ │ ├── bootstrap.js │ │ ├── bootstrap.js.map │ │ ├── bootstrap.min.js │ │ └── bootstrap.min.js.map │ ├── templates │ │ ├── cms │ │ │ ├── base.html │ │ │ ├── book_edit.html │ │ │ ├── book_list.html │ │ │ ├── impression_edit.html │ │ │ └── impression_list.html │ │ └── vulnerability │ │ ├── base.html │ │ ├── week_edit.html │ │ └── week_list.html │ ├── tests.py │ ├── urls.py │ └── views.py ├── db.sqlite3 ├── manage.py ├── mybook │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-36.pyc │ │ ├── settings.cpython-36.pyc │ │ ├── urls.cpython-36.pyc │ │ └── wsgi.cpython-36.pyc │ ├── settings.py │ ├── urls.py │ └── wsgi.py └── vulnerability ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-36.pyc │ ├── admin.cpython-36.pyc │ ├── forms.cpython-36.pyc │ ├── models.cpython-36.pyc │ ├── urls.cpython-36.pyc │ └── views.cpython-36.pyc ├── admin.py ├── apps.py ├── forms.py ├── migrations │ ├── 0001_initial.py │ ├── __init__.py │ └── __pycache__ │ ├── 0001_initial.cpython-36.pyc │ └── __init__.cpython-36.pyc ├── models.py ├── tests.py ├── urls.py └── views.py 20 directories, 94 files $
(week_list.html) {% extends "vulnerability/base.html" %} {% block title %}Week Vulnerability List{% endblock title %} {% block content %} <h4 class="mt-4 border-bottom">Week Vulnerability List</h4> <a href="{% url 'vulnerability:week_add' %}" class="btn btn-primary btn-sm my-3">追加</a> <table class="table table-striped table-bordered"> <thead> <tr> <th scope="col">ID</th> <th scope="col">CVE ID</th> <th scope="col">Base Score</th> <th scope="col">Attack Vector</th> <th scope="col">CWE Type</th> <th scope="col">Description</th> <th scope="col">Published Date</th> <th scope="col">Last Modified Date</th> <th scope="col">Vendor Name</th> <th scope="col">Product Name</th> <th scope="col">Affected Version</th> <th scope="col">Action</th> </tr> </thead> <tbody> {% for week in weeks %} <tr> <th scope="row">{{ week.id }}</th> <td>{{ week.cve_id }}</td> <td>{{ week.base_score }}</td> <td>{{ week.attack_vector }}</td> <td>{{ week.cwe_type }}</td> <td>{{ week.description }}</td> <td>{{ week.published_date }}</td> <td>{{ week.last_modified_date}}</td> <td>{{ week.vendor_name }}</td> <td>{{ week.product_name }}</td> <td>{{ week.affected_version }}</td> <td> <a href="{% url 'vulnerability:week_mod' week_id=week.id %}" class="btn btn-outline-primary btn-sm">Edit</a> #ここのリンクをクリックするとリダイレクトエラーが発生します <a href="{% url 'vulnerability:week_del' week_id=week.id %}" class="btn btn-outline-danger btn-sm">Delete</a> </td> </tr> {% endfor %} </tbody> </table> {% endblock content %}
試したこと
7行目がエラーとなっているので、リンクをcmsにしたり、vulnerabilityに変えたりしましたが、エラーの表示内容に変更はありませんでした。
補足情報(FW/ツールのバージョンなど)
Python3.6.0
Django2.1.3
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。