Реверс для 'anhangdelete' с аргументами '(' ',)' не найден. Приведено 1 рисунков: ['Verwaltung / AnhangDelete / (? P <id>[0-9] +) $'] - PullRequest
0 голосов
/ 27 февраля 2020

Ошибка:

Метод запроса: GET URL запроса: http://127.0.0.1: 8000 / Verwaltung / Anhang / 10 Django Версия: 3.0.1 Тип исключения: NoReverseMatch Значение исключения: обратное значение для 'anhangdelete' с аргументами '(' ',)' не найдено. Попробован 1 шаблон (ов): ['Verwaltung / AnhangDelete / (? P [0-9] +) $'] Местоположение исключения: C: \ Users \ PC \ PycharmProjects \ AddressLizenzbuch \ venv \ lib \ site-packages \ django \ urls \ resolvers.py в _reverse_with_prefix, строка 677 Python Исполняемый файл: C: \ Users \ PC \ PycharmProjects \ AddressLizenzbuch \ venv \ Scripts \ python .exe Python Версия: 3.8.0

views.py

@login_required()
def anhang_view(request, id=None):
    contextoo = {}
    item = Kunden.objects.get(id=id)
    kontaktform_form = KontaktForm(request.POST or None, instance=item)
    creatorform_form = CreateANform()
    contextoo['creatorform_form'] = creatorform_form
    if Kunden.objects.filter(KN=item.KN).exists():
        item14 = Kunden.objects.get(KN=item.KN)
        editkontakto_form = InfoKontaktoForm(request.POST or None, instance=item14)
        contextoo['editkontakto_form'] = editkontakto_form
    if Anhang.objects.filter(KN=item.KN).exists():
        item15 = Anhang.objects.filter(KN=item.KN)
        contextoo['ANform_form'] = item15
    if request.method == 'POST':
        creatorform_form = CreateANform(request.POST)
        if creatorform_form.is_valid():
            cre = creatorform_form.save(commit=True)
            cre.save()
        return redirect('/Verwaltung/KontaktAnlegen')
    else:
        return render(request, 'blog/anhang.html', contextoo)    


@login_required()
def AnhangDeleteView(request, id):
    anh = Anhang.objects.get(id=id)
    anh.delete()
    return redirect(reverse('blog:Anhang'))

urls.py

path('AnhangDelete/<int:id>', views.AnhangDeleteView, name='anhangdelete'),

anhang. html

.
.
.
{% if ANform_form %}
    {% for obj in ANform_form %}
          <table class="table" width="100%" border="0" cellspacing="0" cellpadding="0">
            <thead class="thead-light">
                <tr>
                    <td width="11%" border="0" cellspacing="0" cellpadding="0">
                        <b>
                            {% csrf_token %}
                            {{ obj.Thema }}
                        </b>
                    </td>
                    <td width="15%" border="0" cellspacing="0" cellpadding="0">Username</td>
                    <td width="19%" border="0" cellspacing="0" cellpadding="0">Password</td>
                    <td width="18%" border="0" cellspacing="0" cellpadding="0">E-Mail</td>
                    <td width="37%" border="0" cellspacing="0" cellpadding="0">Anhang</td>
                    <td>
                    </td>
                    <td></td>
                </tr>
            </thead>
            <tbody>
                <td></td>
                <td>
                    {% csrf_token %}
                    {{ obj.Username }}
                </td>
                <td>
                    {% csrf_token %}
                    {{ obj.Password }}
                </td>
                <td>
                    {% csrf_token %}
                    {{ obj.Email }}
                </td>
                <td>
                    {% csrf_token %}
                    {{ obj.Anhang }}
                </td>
                <td>
                    <a href="{% url 'blog:anhangdelete' Kunden.KN %}"><button type="button" class="btn btn-danger">Löschen</button></a> </td>
                </td>
            </tbody>
          </table>
    {% endfor %}
{% endif %}

models.py

class Anhang(models.Model):
    KN = models.IntegerField(unique=False)
    Thema = models.CharField(max_length=100, blank=True, unique=False)
    Username = models.CharField(max_length=100, blank=True, unique=False)
    Password = models.CharField(max_length=100, blank=True, unique=False)
    Email = models.CharField(max_length=100, blank=True, unique=False)
    Anhang = models.CharField(max_length=250, blank=True, unique=False)


class Kunden(models.Model):
    KN = models.IntegerField(unique=True)
    Anrede = models.CharField(max_length=30, blank=True)
    Name = models.CharField(max_length=30, blank=True)
    Vorname = models.CharField(max_length=30, blank=True)
    Infos = models.CharField(max_length=250, default='Notiz:', editable=True)

так ... все мои delete_views работают за исключением этого, потому что обычно они имеют свой источник из "Kunden.id", но этот delete_view ориентируется на Anhang.KN настолько, насколько я думаю, и я не знаю, где проблема ...

TRACEBACK

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/Verwaltung/Anhang/10

Django Version: 3.0.1
Python Version: 3.8.0
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'blog',
 'rlwebs',
 'django_tables2',
 'bootstrap4']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']


Template error:
In template C:\Users\PC\PycharmProjects\AddressLizenzbuch\web\blog\templates\blog\base.html, error at line 0
   Reverse for 'AnhangDelete' with arguments '('',)' not found. 1 pattern(s) tried: ['Verwaltung/AnhangDelete/(?P<id>[0-9]+)$']
   1 : 
   2 : <!DOCTYPE html>
   3 : <html lang="en">
   4 : <div class="p-3 mb-2 bg-secondary text-white">
   5 : 
   6 : <head>
   7 :     <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
   8 :     <meta charset="UTF-8">
   9 :     <title>{% block supertitle %} Home {% endblock %}</title>
   10 :     <!-- Bootstrap Core CSS -->


Traceback (most recent call last):
  File "C:\Users\PC\PycharmProjects\AddressLizenzbuch\venv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
    response = get_response(request)
  File "C:\Users\PC\PycharmProjects\AddressLizenzbuch\venv\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "C:\Users\PC\PycharmProjects\AddressLizenzbuch\venv\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\PC\PycharmProjects\AddressLizenzbuch\venv\lib\site-packages\django\contrib\auth\decorators.py", line 21, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "C:\Users\PC\PycharmProjects\AddressLizenzbuch\web\blog\views.py", line 200, in anhang_view
    return render(request, 'blog/anhang.html', contextoo)
  File "C:\Users\PC\PycharmProjects\AddressLizenzbuch\venv\lib\site-packages\django\shortcuts.py", line 19, in render
    content = loader.render_to_string(template_name, context, request, using=using)
  File "C:\Users\PC\PycharmProjects\AddressLizenzbuch\venv\lib\site-packages\django\template\loader.py", line 62, in render_to_string
    return template.render(context, request)
  File "C:\Users\PC\PycharmProjects\AddressLizenzbuch\venv\lib\site-packages\django\template\backends\django.py", line 61, in render
    return self.template.render(context)
  File "C:\Users\PC\PycharmProjects\AddressLizenzbuch\venv\lib\site-packages\django\template\base.py", line 171, in render
    return self._render(context)
  File "C:\Users\PC\PycharmProjects\AddressLizenzbuch\venv\lib\site-packages\django\template\base.py", line 163, in _render
    return self.nodelist.render(context)
  File "C:\Users\PC\PycharmProjects\AddressLizenzbuch\venv\lib\site-packages\django\template\base.py", line 936, in render
    bit = node.render_annotated(context)
  File "C:\Users\PC\PycharmProjects\AddressLizenzbuch\venv\lib\site-packages\django\template\base.py", line 903, in render_annotated
    return self.render(context)
  File "C:\Users\PC\PycharmProjects\AddressLizenzbuch\venv\lib\site-packages\django\template\loader_tags.py", line 150, in render
    return compiled_parent._render(context)
  File "C:\Users\PC\PycharmProjects\AddressLizenzbuch\venv\lib\site-packages\django\template\base.py", line 163, in _render
    return self.nodelist.render(context)
  File "C:\Users\PC\PycharmProjects\AddressLizenzbuch\venv\lib\site-packages\django\template\base.py", line 936, in render
    bit = node.render_annotated(context)
  File "C:\Users\PC\PycharmProjects\AddressLizenzbuch\venv\lib\site-packages\django\template\base.py", line 903, in render_annotated
    return self.render(context)
  File "C:\Users\PC\PycharmProjects\AddressLizenzbuch\venv\lib\site-packages\django\template\loader_tags.py", line 62, in render
    result = block.nodelist.render(context)
  File "C:\Users\PC\PycharmProjects\AddressLizenzbuch\venv\lib\site-packages\django\template\base.py", line 936, in render
    bit = node.render_annotated(context)
  File "C:\Users\PC\PycharmProjects\AddressLizenzbuch\venv\lib\site-packages\django\template\base.py", line 903, in render_annotated
    return self.render(context)
  File "C:\Users\PC\PycharmProjects\AddressLizenzbuch\venv\lib\site-packages\django\template\defaulttags.py", line 309, in render
    return nodelist.render(context)
  File "C:\Users\PC\PycharmProjects\AddressLizenzbuch\venv\lib\site-packages\django\template\base.py", line 936, in render
    bit = node.render_annotated(context)
  File "C:\Users\PC\PycharmProjects\AddressLizenzbuch\venv\lib\site-packages\django\template\base.py", line 903, in render_annotated
    return self.render(context)
  File "C:\Users\PC\PycharmProjects\AddressLizenzbuch\venv\lib\site-packages\django\template\defaulttags.py", line 209, in render
    nodelist.append(node.render_annotated(context))
  File "C:\Users\PC\PycharmProjects\AddressLizenzbuch\venv\lib\site-packages\django\template\base.py", line 903, in render_annotated
    return self.render(context)
  File "C:\Users\PC\PycharmProjects\AddressLizenzbuch\venv\lib\site-packages\django\template\defaulttags.py", line 443, in render
    url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)
  File "C:\Users\PC\PycharmProjects\AddressLizenzbuch\venv\lib\site-packages\django\urls\base.py", line 87, in reverse
    return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
  File "C:\Users\PC\PycharmProjects\AddressLizenzbuch\venv\lib\site-packages\django\urls\resolvers.py", line 677, in _reverse_with_prefix
    raise NoReverseMatch(msg)

Exception Type: NoReverseMatch at /Verwaltung/Anhang/10
Exception Value: Reverse for 'AnhangDelete' with arguments '('',)' not found. 1 pattern(s) tried: ['Verwaltung/AnhangDelete/(?P<id>[0-9]+)$']

Трассировка выполняется с этим примером кода в anhang. html

<a href="{% url 'blog:AnhangDelete' Anhang.id %}"><button type="button" class="btn btn-danger">Löschen</button></a> </td>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...