Category: Django

Django
2025-03-13 09:25 (14 months ago)
How to Fix Display Issues in Django Admin Inlines After Upgrading to 5.1

Hide a specific `ModelForm` field in a Django 5 Admin Inline while still passing initial values as a dict — combine `formfield_overrides` with `get_initial`.

Django
2024-12-14 04:46 (17 months ago)
Return Login and Redirect Views by Hardcoding Social Account Provider in django-allauth (When Using AWS Cognito, etc.)

How to Create a Login View in Django Allauth Without Specifying the Social Account Backend in the URL

Django
2024-04-15 08:35 (2 years ago)
After Upgrading to Django 5 and Updating Dependencies, SSL: CERTIFICATE_VERIFY_FAILED Error Occurs When Sending Emails

I updated Django to version 5.0 and also updated other libraries. When I executed the code for sending an email, an ssl.SSLCertVerificationError occurred.

DjangoPython
2024-03-28 00:41 (2 years ago)
The "first" and "second" Arguments of assertEqual in Django's Unit Tests are Actually "expected" and "actual"

When looking at the assertEqual method in Django's unit tests, the first argument is named 'first' and the second argument is named 'second'. It appears that there is no difference in the usage of these variables.

DjangoPython
2024-03-24 04:53 (2 years ago)
Fix: pipenv install fails with AttributeError: module 'pkgutil' has no attribute 'ImpImporter' (Python 3.12)

pipenv install throws "AttributeError: module 'pkgutil' has no attribute 'ImpImporter'" on Python 3.12. Run `python3 -m ensurepip --upgrade` in both the global and virtualenv, or rebuild the pipenv environment.

DjangoPython
2023-11-09 03:39 (2 years ago)
対応方法 When using MySQLdb with Python and encountering "symbol not found in flat namespace '_mysql_affected_rows'"

Fix `symbol not found in flat namespace '_mysql_affected_rows'` when importing MySQLdb in Python — rebuild mysqlclient against the right MySQL client library.

Django
2023-10-12 12:41 (2 years ago)
Switching the Logged-in User in Django Using the Django Shell

Here's an overview in English: How to change the user of an already established session using the Django shell. Please do not attempt this in a production environment as it can be dangerous.

Django
2022-12-27 10:15 (3 years ago)
View the Contents of Redis Directly from the Terminal in Django

This article explains how to directly view the contents of Django Redis using the Django shell.

Django
2022-11-18 10:16 (3 years ago)
Reading DB Settings from Django Configuration and Copying Data from Production to Staging with mysqldump

I usually write data copy scripts in bash, but I tried writing one in Python this time and decided to document it.

Django
2022-11-02 12:34 (3 years ago)
Code to Display the Number of URLs in Django

During an IT audit, it was necessary to represent the scale of the application. To achieve this, I decided to consider the total number of URLs in Django as an indicator of the application's scale.

Django
2022-10-17 11:24 (3 years ago)
Manually Creating a Password Reset URL in Django AllAuth

Build a macOS Service (Quick Action) that sends `find` results to the clipboard via `pbcopy` — works back to Big Sur.

Django
2022-09-16 10:11 (3 years ago)
After Updating Django, Migration Fails for oauth2_provider

Use `mkdir -p ... && cd $_` on macOS to chain create-and-enter reliably without race conditions.

Django
2022-09-12 12:21 (3 years ago)
Setting Up a Logger to Output Logs to the Console in Django

Summary of the blog post in English: "Django Logging Configuration: Output to Console Instead of File"

DjangoMySQL
2022-09-11 09:58 (3 years ago)
Tips for Solving the 2027 Malformed Packet Error in MySQL

Return a common post-login redirect target in Django Allauth without specifying a SocialAccount — how `LOGIN_REDIRECT_URL` behaves and how to override it.

DjangoDockerPython
2022-09-03 11:03 (3 years ago)
Changed Django's Docker Environment from Alpine + uWSGI to Debian + Daphne → Ended up with uvicorn After All

Why switch a Django Docker image from Alpine + uWSGI to Debian + Daphne (ASGI), with example Dockerfile and Kubernetes manifest changes.

Django
2022-08-06 02:09 (3 years ago)
Display a Warning When Attempting to Navigate Away with Unsaved Changes in Django Mezzanine's TinyMCE

If you are using version 4 of tinyMCE, you can add an onChange event in the setup option of tinyMCE.init.

Django
2022-03-21 08:57 (4 years ago)
To Create a Request in Django Unit Tests, Retrieving the wsgi_request from the Response is Convenient

When creating unit tests in Django, there are times when you need a Request (WSGIRequest).

Django
2021-12-11 13:51 (4 years ago)
If you see "cannot import name 'ugettext_lazy'" in Django, Django 4.0 might be installed

Here is the solution for resolving the ImportError: cannot import name 'ugettext_lazy' from 'django.utils.translation' that occurs when running manage.py hoge in Django.

DjangoMySQL
2021-11-14 11:10 (4 years ago)
I removed NO_ENGINE_SUBSTITUTION because I got 'Lost connection to MySQL server during query' in Django

If a Django MySQL connection still hits 'No DB engine substitution' despite setting `ENGINE` to `django.db.backends.mysql`, here is the root cause and fix.

Django
2021-01-26 08:21 (5 years ago)
I want to add custom HTML to Django Admin Inlines

Insert a custom HTML snippet or help text into a Django Admin Inline formset (TabularInline / StackedInline) — implementation patterns.

Django
2021-01-20 11:10 (5 years ago)
Create Another Admin Site in Django

If you want to create a different URL for Django's Admin while keeping /admin/ intact: Create an instance using `from django.contrib.admin import AdminSite` and `site = AdminSite(name='staff')`.

DjangoMySQL
2020-11-08 10:53 (5 years ago)
mysql django.db.utils.InterfaceError: (0, '')

If you encounter the django.db.utils.InterfaceError: "(0, '')" error When this error occurs intermittently during get operations depending on the table or record, it might be due to a mismatch in the connection character encoding.

DjangoMySQLPython
2020-10-11 02:52 (5 years ago)
NameError: name '_mysql' is not defined in Python (Django) (Especially During Local Development)

If a Django project that has been working until now fails to start after a long time with the following error: ``` version_info, _mysql.version_info, _mysql.__file__ NameError: name '_mysql' is not defined ```

Django
2020-09-13 06:57 (5 years ago)
Starting Django on Docker Alpine Results in django.db.utils.OperationalError: (2000, 'Unknown MySQL error')

When running `python3 ./manage.py runserver 8080`, I encountered the error `django.db.utils.OperationalError: (2000, 'Unknown MySQL error')`. This error occurs when the `OPTIONS` setting includes `'charset': 'utf8mb4'`.

Django
2020-05-19 06:34 (6 years ago)
Manually Operating Viewsets in Django Rest Framework to Retrieve Serialized Data

Introduction to Python Code for APIView.

Django
2020-05-18 02:16 (6 years ago)
対応方法 When MySQL AutoIncrement Runs Out

MySQLdb._exceptions.OperationalError: (1467, 'Failed to read auto-increment value from storage engine') In Django, when you specify an implicit id, the above error occurs if the auto increment value reaches its upper limit.

Django
2019-12-25 06:14 (6 years ago)
Upgrading to Django 3: from_db_value() missing 1 required positional argument: 'context' Error Occurs

Fix `from_db_value() missing 1 required positional argument: 'context'` on custom Django fields after upgrading to Django 3 — adapt to the removed `context` arg.

Django
2019-06-22 13:07 (6 years ago)
When Django's DecimalField quantize Fails on Alpine Linux

Stop PyCharm / JetBrains project view from opening files on a single click — how to require a double click instead.

Django
2019-03-25 23:57 (7 years ago)
How to Use freezegun in Django Tests to Set the Date One Day Ahead with USE_TZ=True

Use freezegun in Django tests so that "one day later" or relative offsets work correctly under `USE_TZ=True`.

DjangoPHP
2019-03-14 15:19 (7 years ago)
Using Vue.js Webpack Dev Server Proxy for Social Provider Authentication with Django + Python Social Auth

When developing with Vue, if you are running a webpack dev server and using Django for the API backend along with Django's authentication using Python social auth and an external Auth provider, you may encounter an issue.

Django
2018-09-27 02:37 (7 years ago)
Preventing "table already exists" error when canceling migrations in Django tests

Avoid `table already exists` failures in Django tests when running with `--keepdb` after cancelling migrations — how to forcibly reset the test DB migration state.

Django
2018-09-25 10:10 (7 years ago)
Unit Testing Abstract Models in Django

Django: Best way to unit-test an abstract model - Stack Overflowhttps://stackoverflow.com/questions/4281670/django-best-way-to-unit-test-an-abstract-model

Django
2018-07-12 11:24 (7 years ago)
Issues with Redirect URLs Being HTTP Instead of HTTPS in Python Social Auth Django or AllAuth

One-liner to count upgradable packages with `apt list --upgradable`, plus a shell script to surface the number in the MOTD login banner.

Django
2018-05-15 03:24 (8 years ago)
Creating a ForeignKey Across Databases in Django 2.0

※ This does not mean creating constraints in an RDB. It simply means creating a ForeignKey field that works for now.

Django
2018-03-29 06:37 (8 years ago)
NameError: name 'module1' is not defined when running ./manage.py test in Django

Make Django's `request.build_absolute_uri()` return HTTPS behind Apache + ELB — `USE_X_FORWARDED_HOST` and `SECURE_PROXY_SSL_HEADER` settings.

Django
2018-02-05 08:02 (8 years ago)
How to Unit Test a Django Model with managed = False

When using Django, setting `Meta: managed = False` in a model can sometimes lead to a `ProgrammingError` during unit tests from other apps when attempting operations such as `create()`. This is a memo on how to address this issue.

Django
2018-01-11 05:48 (8 years ago)
When Updating Django from 1.6 to 2.0, django.db.utils.InternalError: (1364, "Field 'name' doesn't have a default value") Occurs During Migration

When I tried to migrate a project using Python 2.7 + Django 1.6 to Python 3.5 + Django 2.0 and recreated the migration files, running ./manage.py migrate resulted in the following error:

DjangoLinux
2017-09-11 08:35 (8 years ago)
Install libgconf2 if Python Selenium ChromeDriver Fails to Start with Error 127

On Ubuntu 14.04, Selenium ChromeDriver exits with status 127 when `libgconf-2.so.4` is missing. Run `sudo apt install libgconf2-4` to fix it.

DjangoPython
2017-09-01 02:10 (8 years ago)
What to Do When You Encounter AuthAlreadyAssociated with Django Social Auth

I'm writing this down because I always get flustered.

Django
2017-05-09 08:49 (9 years ago)
Base View Class for Downloading CSV in SJIS with Django

Base View Class for Downloading SJIS CSV in Django

Django
2017-02-26 10:25 (9 years ago)
Creating Custom Filters in Django Admin

Using SimpleListFilter for Easy Implementation

Django
2017-01-26 04:11 (9 years ago)
Mistakes When Searching MySQL with datetime in Django Due to Time Zone Mismatch

Since I often make mistakes, here's a note.

DjangoLinux
2016-09-16 03:24 (9 years ago)
Failure of Django CSRF Token Authentication: ELB -> Apache2 -> uwsgi

Fix Django CSRF token failure on an AWS ELB → Apache2 → uWSGI stack. The pitfall is the HTTP/HTTPS scheme detection when switching from mod_wsgi to uWSGI.

DjangoPython
2016-06-20 08:35 (9 years ago)
Outputting Shift-JIS CSV with Django

How to return a Shift-JIS (CP932) CSV download response from Django on Python 3 — write to StringIO as Unicode first, then encode to cp932 in one shot.

Django
2015-12-22 09:57 (10 years ago)
Using Django RedirectView Inline in URLs to Redirect While Preserving URL Path

I want to redirect people who access /url-path-before/feature/hoge/ to /url-path-after/feature/hoge/.

Django
2015-11-27 00:40 (10 years ago)
Decorator to Prevent Duplicate Execution of Django Management Commands

If your Twitter Developer API account is banned / suspended, how to write an appeal to Twitter support and what to include in the reappeal.

Django
2015-10-29 08:35 (10 years ago)
Trying Out Django TemplateView with Extensive Use of @cached_property

Sample remote interpreter / SSH setup for developing Rails inside a Vagrant VM using RubyMine.

Django
2015-10-15 10:10 (10 years ago)
Paging Django Model Instances Queried with Complex Filters Using Paginator

Page through Django model instances retrieved via a complex query (raw SQL or composed Q objects) using Paginator, with a working implementation pattern.

Django
2015-09-03 11:48 (10 years ago)
Create a Full-Text Index in Migration Files with Django 1.7

This is a method to create a full-text index in MySQL using the DB migration feature in Django 1.7 and above.

Django
2015-07-07 05:38 (10 years ago)
How to Replace Strings in Django TemplateView

```html Here are two methods to output an HTML template as it is using Django's TemplateView class, but replacing strings in the output result at once.

Django
2015-05-29 11:31 (11 years ago)
Create a Simple Login URL with Django

url(r'^login/', 'django.contrib.auth.views.login', name='login', kwargs={'template_name': 'admin/login.html', 'extra_context': {'next': '/'}}), Write this link in the template as follows,

Django
2015-05-10 07:19 (11 years ago)
Using reStructuredText with Mezzanine

There is a system called Mezzanine for building a CMS on Python + Django. By default, blog entries are written using a WYSIWYG HTML editor, but I wanted to write them using reStructured Text (reST, rst), so I did some research.

Django
2013-09-21 04:04 (12 years ago)
Add Custom HTML to Django Admin Form Templates

1. Define change_form_template in the admin.py module Specify the location of the custom template

Django
2011-09-10 11:32 (14 years ago)
recreate-migration: BASH Function to Recreate Migration

Rollback the migration, delete all migration scripts, and then redo the schema migrations.

Django
2011-09-10 11:20 (14 years ago)
Template Tags for Time Branching: ifbefore, ifafter, ifafterbefore

```python

Django
2011-06-21 06:24 (14 years ago)
Creating Dummy Text with Lorem Ipsum

```html Using template tags like lorem, you can create dummy data for articles utilizing the django.contrib.webdesign.lorem_ipsum package.

Django
2011-06-20 17:14 (14 years ago)
Django admin sets default form field values based on GET parameters

When you pass a GET query like

Django
2011-06-17 07:09 (14 years ago)
Management Command to Visualize Model Relationships

```python

Django
2011-06-17 01:10 (14 years ago)
Remove the Delete Button from the Django Admin Interface

Disable Deletion from List Checkboxes Create a file like common/admins.py

Categories

Archive