Category: Django
This blog post covers the steps to build a Python 3.12 environment and discusses how to create a new virtual environment using Pipenv. It focuses on a specific issue that might arise when running the `pipenv install` command, which results in the error: AttributeError: module 'pkgutil' has no attribute 'ImpImporter'. Did you mean: 'zipimporter'? The post provides a detailed checklist and solutions to address this error.
Here is an English translation of the summary for a blog post on how to address the error "symbol not found in flat namespace '_mysql_affected_rows'" when attempting to use MySQLdb in Python: --- **How to Address the "symbol not found in flat namespace '_mysql_affected_rows'" Error When Using MySQLdb in Python** In this blog post, we will discuss the steps to resolve the error "symbol not found in flat namespace '_mysql_affected_rows'" that may occur when attempting to use the MySQLdb library in Python. This error typically arises due to issues with the MySQLdb installation or compatibility problems between the library and your system. We will explore various troubleshooting methods and provide detailed instructions to help you get MySQLdb running smoothly.
### How to Add Custom HTML to Django Admin Inlines If you want to add custom HTML to Django Admin inlines, simply defining custom properties in the Admin or model class and trying to handle them with `fields` or `fieldsets` in the Inline class won't work smoothly. It's better to straightforwardly extend the inline templates.
Freezegun is a Python library that hooks into the datetime module to allow for testing scenarios that require manipulating the current time, such as simulating the next day. When running tests in Django that assume the next day, there can be issues, such as tests failing before 9:00 AM if the system is set to the JST timezone.
During testing of Django Mezzanine Cartridge, I encountered an issue when cancelling a migration. I had configured the settings in a certain way, but due to problems involving the ManyToMany field's `through=`, the process halted with a "table already exists" error, preventing the creation of the table and thus stopping the tests.
Originally, the configuration was AWS ELB -> Apache2 -> mod_wsgi, but after changing the Django server to use uWSGI, the configuration became AWS ELB -> Apache2 -> uWSGI. After this change, I started experiencing issues with Django's CSRF authentication, such as when submitting a login form. When I checked with DEBUG = True, I saw the following message: Access Forbidden (403) The request was aborted due to failure in CSRF verification. Help Reason given for failure: Referer checking failed - https://example.com.com/some-path/ does not match any trusted origins. In general, this can occur when there is a genuine Cross-Site Request Forgery, or when Django's CSRF mechanism has not been used correctly. For POST forms, you need to ensure: Your browser is accepting cookies. The view function passes a request to the template's render method. In the template, there is a {% csrf_token %} template tag inside each POST form that targets an internal URL. If you are not using CsrfViewMiddleware, then you must use csrf_protect on any views that use the csrf_token template tag, as well as those that accept the POST data. You're seeing the help section of this page because you have DEBUG = True in your Django settings file. Change that to False, and only the initial error message will be displayed. You can customize this page using the CSRF_FAILURE_VIEW setting. The ELB receives HTTPS, sends requests to Apache on port 80, and uWSGI is listening for HTTP protocol (not uWSGI protocol). The Apache configuration is as follows: ProxyPass / http://127.0.0.1:8081/ ProxyPassReverse / http://127.0.0.1:8081/ Alias /static/ /var/django/xxxxx/staticfiles/ ProxyPass /static/ ! Something like this. Upon searching the Django code, I found in csrf.py: REASON_BAD_REFERER = "Referer checking failed - %s does not match any trusted origins." It appears that adding the domain to CSRF_TRUSTED_ORIGINS should work. CSRF_TRUSTED_ORIGINS = [".example.com"] This should do the trick.
class Content(models.Model): content_name = models.CharField(...) group_id = models.PositiveIntegerField(...) volume_number = models.PositiveIntegerField(...) ... Assuming we have a typical Django model class, we want to search for its instances using a complex SQL query in a single shot. The results should be displayed on a web page, but since many rows are expected, we want to display a paginator.
Recent Posts
- Skill + CLI over MCP: Replacing Sentry MCP with a multi-profile CLI wrapper
- Turning Raspberry Pi into a Signage Display with Playwright and Chromium Kiosk Mode
- Docker 29 breaks docker push to ECR with 403 Forbidden on GitHub Actions
- How to Add "Copy Full File Path to Clipboard" to Finder's Services Menu
- How to turn Orange Pi Zero 2W into a Web Signage Display
Recent Deliverables
Categories
- Django (66)
- Python (49)
- mac (22)
- Linux (17)
- kubernetes (15)
- iOS (11)
- MySQL (10)
- Raspberry-Pi (8)
- AWS (7)
- PHP (6)
- Javascript (5)
- PC/Etc (5)
- Docker (5)
- Android (4)
- Bicycle (4)
- (4)
- nuxt (3)
- css (3)
- nginx (3)
- Bootstrap (3)
- Flutter (3)
- Shellscript(Bash/Zsh) (3)
- Making (2)
- Windows (2)
- HTML (2)
- (1)
- Ebook (1)
- Rails (1)
- Microcontrollers (1)
- less (1)
- Ansible (1)
- (1)
- (1)