DoesNotExist at /admin/blog/blog/add/: blog matching query does not exist

Enerel Amgalan enerel.amgalan at yahoo.com
Tue Sep 13 01:41:46 EDT 2022


unsubscribe 

-Bat

> On Sep 12, 2022, at 14:32, mailinglists at vanwingerde.nl wrote:
> 
> Suddenly I can no longer add blogs to Django. Django says 'blog
> matching query does not exist'. That seems strange to me because I want
> to add something to the database and not request a blog. What could be
> going on here?
> 
> admin.py:
> class blogadmin(admin.ModelAdmin):
>    def save_model(self, request, obj, form, change):
>        if not change:
>            obj.added_by_user = request.user.username
>            obj.ip_added = request.META['REMOTE_ADDR']
>            if obj.ip_added == '127.0.0.1':
>                obj.ip_added = request.META['HTTP_X_FORWARDED_FOR']
>            obj.publish = False
>            del obj.publish_date
>        else:
>            obj.changed_by_user = request.user.username
>            obj.ip_changed = request.META['REMOTE_ADDR']
>            if obj.ip_changed == '127.0.0.1':
>                obj.ip_changed = request.META['HTTP_X_FORWARDED_FOR']
>            if obj.publish == True:
>                if not obj.publish_date:
>                    obj.publish_date = obj.datetime_changed
>        super(blogadmin,self).save_model(request, obj, form, change)
> 
> I can add text, photographs etc., but no blogs.
> 
> Notifications:
> DoesNotExist at /admin/blog/blog/add/
> 
> blog matching query does not exist.
> 
> Request Method:    POST
> Request URL:    http://127.0.0.1:8001/admin/blog/blog/add/
> Django Version:    4.1.1
> Exception Type:    DoesNotExist
> Exception Value:    
> 
> blog matching query does not exist.
> 
> Traceback
> Environment:
> Request Method: POST
> Request URL: http://127.0.0.1:8001/admin/blog/blog/add/
> 
> Django Version: 4.1.1
> Python Version: 3.10.5
> Installed Applications:
> ['grappelli',
> 'django.contrib.admin',
> 'django.contrib.admindocs',
> 'django.contrib.auth',
> 'django.contrib.contenttypes',
> 'django.contrib.sessions',
> 'django.contrib.messages',
> 'django.contrib.staticfiles',
> 'blog.apps.BlogConfig']
> 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',
> 'django.contrib.admindocs.middleware.XViewMiddleware']
> 
> Traceback (most recent call last):
>  File
> "/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/core/handlers/exception.py",
> line 55, in inner response = get_response(request) File
> "/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/core/handlers/base.py",
> line 197, in _get_response response = wrapped_callback(request,
> *callback_args, **callback_kwargs) File
> "/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/contrib/admin/options.py",
> line 686, in wrapper return self.admin_site.admin_view(view)(*args,
> **kwargs) File
> "/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/utils/decorators.py",
> line 133, in _wrapped_view response = view_func(request, *args,
> **kwargs) File
> "/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/views/decorators/cache.py",
> line 62, in _wrapped_view_func response = view_func(request, *args,
> **kwargs) File
> "/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/contrib/admin/sites.py",
> line 242, in inner return view(request, *args, **kwargs) File
> "/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/contrib/admin/options.py",
> line 1890, in add_view return self.changeform_view(request, None,
> form_url, extra_context) File
> "/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/utils/decorators.py",
> line 46, in _wrapper return bound_method(*args, **kwargs) File
> "/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/utils/decorators.py",
> line 133, in _wrapped_view response = view_func(request, *args,
> **kwargs) File
> "/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/contrib/admin/options.py",
> line 1750, in changeform_view return self._changeform_view(request,
> object_id, form_url, extra_context) File
> "/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/contrib/admin/options.py",
> line 1802, in _changeform_view self.save_model(request, new_object,
> form, not add) File "/var/django/liakoster.nl/blog-1/blog/admin.py",
> line 26, in save_model super(blogadmin,self).save_model(request, obj,
> form, change) File
> "/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/contrib/admin/options.py",
> line 1225, in save_model obj.save() File
> "/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/db/models/base.py",
> line 831, in save self.save_base( File
> "/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/db/models/base.py",
> line 882, in save_base updated = self._save_table( File
> "/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/db/models/base.py",
> line 1025, in _save_table results = self._do_insert( File
> "/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/db/models/base.py",
> line 1066, in _do_insert return manager._insert( File
> "/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/db/models/manager.py",
> line 85, in manager_method return getattr(self.get_queryset(),
> name)(*args, **kwargs) File
> "/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/db/models/query.py",
> line 1790, in _insert return
> query.get_compiler(using=using).execute_sql(returning_fields) File
> "/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/db/models/sql/compiler.py",
> line 1656, in execute_sql for sql, params in self.as_sql(): File
> "/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/db/models/sql/compiler.py",
> line 1580, in as_sql value_rows = [ File
> "/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/db/models/sql/compiler.py",
> line 1581, in <listcomp> [ File
> "/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/db/models/sql/compiler.py",
> line 1582, in <listcomp> self.prepare_value(field,
> self.pre_save_val(field, obj)) File
> "/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/db/models/sql/compiler.py",
> line 1530, in pre_save_val return field.pre_save(obj, add=True) File
> "/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/db/models/fields/__init__.py",
> line 1548, in pre_save return super().pre_save(model_instance, add)
> File
> "/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/db/models/fields/__init__.py",
> line 1411, in pre_save return super().pre_save(model_instance, add)
> File
> "/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/db/models/fields/__init__.py",
> line 905, in pre_save return getattr(model_instance, self.attname) File
> "/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/db/models/query_utils.py",
> line 178, in __get__ instance.refresh_from_db(fields=[field_name]) File
> "/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/db/models/base.py",
> line 741, in refresh_from_db db_instance = db_instance_qs.get() File
> "/var/django/liakoster.nl/blog-1/lib/python3.10/site-packages/django/db/models/query.py",
> line 650, in get raise self.model.DoesNotExist(
> 
> Exception Type: DoesNotExist at /admin/blog/blog/add/
> Exception Value: blog matching query does not exist.
> -- 
> https://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list