Coverage for app/venv/lib/python3.14/site-packages/weblate/wsgi.py: 87%
13 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 07:15 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 07:15 +0000
1# Copyright © Michal Čihař <michal@weblate.org>
2#
3# SPDX-License-Identifier: GPL-3.0-or-later
5"""
6WSGI config for weblate project.
8This module contains the WSGI application used by Django's development server
9and any production WSGI deployments. It should expose a module-level variable
10named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
11this application via the ``WSGI_APPLICATION`` setting.
13Usually you will have the standard Django WSGI application here, but it also
14might make sense to replace the whole Django WSGI application with a custom one
15that later delegates to the Django one. For example, you could introduce WSGI
16middleware here, or combine a Django application with an application of another
17framework.
18"""
20from __future__ import annotations
22import os
23from typing import TYPE_CHECKING
25from django.core.wsgi import get_wsgi_application
27if TYPE_CHECKING: 27 ↛ 28line 27 didn't jump to line 28 because the condition on line 27 was never true
28 from django.urls import URLPattern, URLResolver
31def preload_url_patterns() -> list[URLPattern | URLResolver]:
32 """
33 Ensure Django URL resolver is loaded.
35 This avoids expensive load with a first request and makes memory sharing work
36 better between uwsgi workers.
37 """
38 from django.conf import settings
39 from django.urls import get_resolver
41 return get_resolver(settings.ROOT_URLCONF).url_patterns
44os.environ.setdefault("DJANGO_SETTINGS_MODULE", "weblate.settings")
46# This application object is used by any WSGI server configured to use this
47# file. This includes Django's development server, if the WSGI_APPLICATION
48# setting points here.
49application = get_wsgi_application()
50preload_url_patterns()