B
B
BEKa T2019-04-20 16:24:56
Django
BEKa T, 2019-04-20 16:24:56

DJ CRUD update?

When going to the post editing page, it gives an error, and tags can be changed without problems,
although both (post, tag) use the same
Traceback mixin

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/posts/new-post-1555763604/update/

Django Version: 2.1.5
Python Version: 3.7.2
Installed Applications:
['blog',
 'engine',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles']
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']



Traceback:

File "/usr/local/lib/python3.7/site-packages/django/core/handlers/exception.py" in inner
  34.             response = get_response(request)

File "/usr/local/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
  126.                 response = self.process_exception_by_middleware(e, request)

File "/usr/local/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
  124.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/usr/local/lib/python3.7/site-packages/django/views/generic/base.py" in view
  68.             return self.dispatch(request, *args, **kwargs)

File "/usr/local/lib/python3.7/site-packages/django/views/generic/base.py" in dispatch
  88.         return handler(request, *args, **kwargs)

Exception Type: TypeError at /posts/new-post-1555763604/update/
Exception Value: get() got an unexpected keyword argument 'slug'

68f629e2-28dc-4474-9a29-6fa14234b2c5.png
urls.py
from django.urls import path
from . views import *

urlpatterns = [
  path('', index, name='main_url'),

  path('posts/', post, name='posts_url'),
  path('posts/create/', PostCreate.as_view(), name='post_create_url'),
  path('posts/<str:slug>/update/', PostUpdate.as_view(), name='post_update_url'),
  path('posts/<str:slug>/', PostInfo.as_view(), name='post_url'),

  path('tags/', tag, name='tags_url'),
  path('tags/create/', TagCreate.as_view(), name='tag_create_url'),
  path('tags/<str:slug>/', TagInfo.as_view(), name='tag_url'),
  path('tags/<str:slug>/update/', TagUpdate.as_view(), name='tag_update_url'),
]

post_update.html
{% extends 'main/index.html' %}

{% block title %}
  Update post
{% endblock %}

{% block content %}



  <form action="{{ post.get_update_url }}" method="POST">
    
      {% csrf_token %}

      {% for field in form %}
      
        <div class="form-group">
          
          {% if field.errors %}
            <div class="alert alert-danger">{{ field.errors }}</div>
          {% endif %}
          
          {{ field.label }}
            {{ field }}

        </div>
      {% endfor %}

    <a href=""><button type="submit" class="btn btn-primary">Изменить пост</button></a>

  </form>



{% endblock %}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
TyzhSysAdmin, 2017-03-08
@POS_troi

Test the screw (vicrotia, mhdd), if everything is in order, then stop hitting the laptop during operation :)
Another fault may be the cable of the screw.
Do not produce questions How to fix recovery win 10 error?

K
Konstantin Stepanov, 2017-03-08
@koronabora

You need to put smart here.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question