#๐ help with my error i cant seem to locate whats causing the issue
7 messages ยท Page 1 of 1 (latest)
@potent cedar
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
the code was working before but when i was making changes to anoither app when i went back to this ferature suddenly it stopped working
myapp/middleware.py
from django.utils.deprecation import MiddlewareMixin
from django.conf import settings
from django.db import connections
import json
import os
class DynamicDatabaseMiddleware(MiddlewareMixin):
def process_request(self, request):
branch_name = request.POST.get('branch_name')
if branch_name:
db_name = f'branch_{branch_name.lower()}'
if db_name in settings.DATABASES:
request.db_name = db_name
else:
# Handle missing database configuration (optional: log a warning or create the DB)
request.db_name = None
else:
request.db_name = None
def process_response(self, request, response):
db_name = getattr(request, 'db_name', None)
if db_name and db_name in connections:
connections[db_name].close()
return response
heres my middle ware
it seems i saw that wasa cauising the issue but can someone explain to me what may i have done wrong to be causing this ussue when i deleted the json file that had the dynamic databses suddenly it worked
@potent cedar
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.