From 32e797bce7fdf49592a9caedbcfcaffd5906c859 Mon Sep 17 00:00:00 2001 From: Nika Date: Mon, 29 Dec 2025 04:26:49 +0300 Subject: [PATCH] Add project files --- bot/__init__.py | 0 bot/admin.py | 3 + bot/apps.py | 5 ++ bot/handlers.py | 85 +++++++++++++++++++++++++++ bot/management/__init__.py | 0 bot/management/commands/__init__.py | 0 bot/management/commands/runbot.py | 28 +++++++++ bot/migrations/__init__.py | 0 bot/models.py | 3 + bot/router.py | 44 ++++++++++++++ bot/templates/bot/back.html | 4 ++ bot/templates/bot/lang_menu.html | 8 +++ bot/templates/bot/menu.html | 10 ++++ bot/tests.py | 3 + bot/utils.py | 40 +++++++++++++ bot/views.py | 3 + config/__init__.py | 0 config/asgi.py | 16 +++++ config/settings.py | 90 +++++++++++++++++++++++++++++ config/urls.py | 22 +++++++ config/wsgi.py | 16 +++++ locale/de/LC_MESSAGES/django.po | 50 ++++++++++++++++ locale/en/LC_MESSAGES/django.po | 50 ++++++++++++++++ locale/fr/LC_MESSAGES/django.po | 50 ++++++++++++++++ locale/ru/LC_MESSAGES/django.po | 50 ++++++++++++++++ manage.py | 22 +++++++ 26 files changed, 602 insertions(+) create mode 100644 bot/__init__.py create mode 100644 bot/admin.py create mode 100644 bot/apps.py create mode 100644 bot/handlers.py create mode 100644 bot/management/__init__.py create mode 100644 bot/management/commands/__init__.py create mode 100644 bot/management/commands/runbot.py create mode 100644 bot/migrations/__init__.py create mode 100644 bot/models.py create mode 100644 bot/router.py create mode 100644 bot/templates/bot/back.html create mode 100644 bot/templates/bot/lang_menu.html create mode 100644 bot/templates/bot/menu.html create mode 100644 bot/tests.py create mode 100644 bot/utils.py create mode 100644 bot/views.py create mode 100644 config/__init__.py create mode 100644 config/asgi.py create mode 100644 config/settings.py create mode 100644 config/urls.py create mode 100644 config/wsgi.py create mode 100644 locale/de/LC_MESSAGES/django.po create mode 100644 locale/en/LC_MESSAGES/django.po create mode 100644 locale/fr/LC_MESSAGES/django.po create mode 100644 locale/ru/LC_MESSAGES/django.po create mode 100644 manage.py diff --git a/bot/__init__.py b/bot/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bot/admin.py b/bot/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/bot/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/bot/apps.py b/bot/apps.py new file mode 100644 index 0000000..f31fdd5 --- /dev/null +++ b/bot/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class BotConfig(AppConfig): + name = 'bot' diff --git a/bot/handlers.py b/bot/handlers.py new file mode 100644 index 0000000..e25105e --- /dev/null +++ b/bot/handlers.py @@ -0,0 +1,85 @@ +# bot/handlers.py +from telegram import Update +from telegram.ext import ContextTypes +from django.utils import translation +from django.utils.translation import gettext as _ +from .utils import render_keyboard, render_message +from .router import router + +# 1. Сценарий: Меню +async def start(update: Update, context: ContextTypes.DEFAULT_TYPE): + # Установка языка по умолчанию + context.user_data['lang'] = 'ru' + + keyboard = render_keyboard('bot/menu.html') + text = _("Добро пожаловать! Выберите действие:") + + await update.message.reply_text(text, reply_markup=keyboard) + +# Обработчики callback-ов через наш роутер + +@router.route('set_lang') +async def set_language_menu(update: Update, context: ContextTypes.DEFAULT_TYPE): + # Показываем меню выбора языка + keyboard = render_keyboard('bot/lang_menu.html') + await update.callback_query.edit_message_text( + _("Выберите язык интерфейса:"), + reply_markup=keyboard + ) + +@router.route('lang_ru') +async def lang_ru(update: Update, context: ContextTypes.DEFAULT_TYPE): + context.user_data['lang'] = 'ru' + translation.activate('ru') + await show_main_menu(update, _("Язык сменен на Русский")) + +@router.route('lang_en') +async def lang_en(update: Update, context: ContextTypes.DEFAULT_TYPE): + context.user_data['lang'] = 'en' + translation.activate('en') + await show_main_menu(update, _("Language changed to English")) + +@router.route('lang_fr') +async def lang_fr(update: Update, context: ContextTypes.DEFAULT_TYPE): + context.user_data['lang'] = 'fr' + translation.activate('fr') + await show_main_menu(update, _("Язык сменен на Французский")) + +@router.route('lang_de') +async def lang_de(update: Update, context: ContextTypes.DEFAULT_TYPE): + context.user_data['lang'] = 'de' + translation.activate('de') + await show_main_menu(update, _("Язык сменен на Немецкий")) + +@router.route('profile') +async def profile(update: Update, context: ContextTypes.DEFAULT_TYPE): + user = update.effective_user + text = _("Ваш профиль:\nID: {id}\nИмя: {name}").format(id=user.id, name=user.first_name) + + keyboard = render_keyboard('bot/back.html') + await update.callback_query.edit_message_text(text, reply_markup=keyboard) + +@router.route('help') +async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE): + # Текст помощи (можно тоже вынести в HTML, но для простоты тут текст) + text = _("ℹ️ *Справка*\n\n" + "Это демонстрационный бот на Django.\n" + "Вы можете менять язык интерфейса и смотреть профиль.\n\n" + "Версия: 1.0") + + # Используем кнопку "Назад", которая у нас уже есть + keyboard = render_keyboard('bot/back.html') + + await update.callback_query.edit_message_text( + text, + reply_markup=keyboard, + parse_mode='Markdown' + ) + +@router.route('main_menu') +async def back_to_main(update: Update, context: ContextTypes.DEFAULT_TYPE): + await show_main_menu(update, _("Главное меню")) + +async def show_main_menu(update, text): + keyboard = render_keyboard('bot/menu.html') + await update.callback_query.edit_message_text(text, reply_markup=keyboard) \ No newline at end of file diff --git a/bot/management/__init__.py b/bot/management/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bot/management/commands/__init__.py b/bot/management/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bot/management/commands/runbot.py b/bot/management/commands/runbot.py new file mode 100644 index 0000000..27eb332 --- /dev/null +++ b/bot/management/commands/runbot.py @@ -0,0 +1,28 @@ +# bot/management/commands/runbot.py +from django.core.management.base import BaseCommand +from django.conf import settings +from telegram.ext import ApplicationBuilder, CommandHandler, CallbackQueryHandler +from bot.handlers import start, router +import logging + +class Command(BaseCommand): + help = 'Запускает Telegram бота' + + def handle(self, *args, **options): + # Логирование для отладки + logging.basicConfig( + format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', + level=logging.INFO + ) + + print("Starting bot...") + + application = ApplicationBuilder().token(settings.TELEGRAM_TOKEN).build() + + # Регистрация хендлеров + application.add_handler(CommandHandler("start", start)) + + # Все callback-и идут в наш роутер + application.add_handler(CallbackQueryHandler(router.handle)) + + application.run_polling() \ No newline at end of file diff --git a/bot/migrations/__init__.py b/bot/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bot/models.py b/bot/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/bot/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/bot/router.py b/bot/router.py new file mode 100644 index 0000000..3335531 --- /dev/null +++ b/bot/router.py @@ -0,0 +1,44 @@ +import logging +from django.utils import translation + +logger = logging.getLogger(__name__) + +class CallbackRouter: + def __init__(self): + self.routes = {} + + def route(self, pattern): + """Декоратор для регистрации обработчика callback""" + def decorator(func): + self.routes[pattern] = func + return func + return decorator + + async def handle(self, update, context): + query = update.callback_query + await query.answer() + + data = query.data + # Простой протокол: "action:payload" + action = data.split(':')[0] + + handler = self.routes.get(action) + if handler: + # Берем язык из данных пользователя (по умолчанию ru) + user_lang = context.user_data.get('lang', 'ru') + translation.activate(user_lang) + + try: + await handler(update, context) + except Exception as e: + logger.error(f"Error in handler {action}: {e}") + finally: + translation.deactivate() + else: + try: + await query.edit_message_text("Неизвестная команда / Unknown command") + except Exception: + pass + +# Глобальный объект роутера, который мы импортируем в handlers.py +router = CallbackRouter() \ No newline at end of file diff --git a/bot/templates/bot/back.html b/bot/templates/bot/back.html new file mode 100644 index 0000000..9711f5f --- /dev/null +++ b/bot/templates/bot/back.html @@ -0,0 +1,4 @@ +{% load i18n %} + \ No newline at end of file diff --git a/bot/templates/bot/lang_menu.html b/bot/templates/bot/lang_menu.html new file mode 100644 index 0000000..ed5b0fb --- /dev/null +++ b/bot/templates/bot/lang_menu.html @@ -0,0 +1,8 @@ +{% load i18n %} + \ No newline at end of file diff --git a/bot/templates/bot/menu.html b/bot/templates/bot/menu.html new file mode 100644 index 0000000..5edf421 --- /dev/null +++ b/bot/templates/bot/menu.html @@ -0,0 +1,10 @@ +{% load i18n %} + \ No newline at end of file diff --git a/bot/tests.py b/bot/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/bot/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/bot/utils.py b/bot/utils.py new file mode 100644 index 0000000..17303b1 --- /dev/null +++ b/bot/utils.py @@ -0,0 +1,40 @@ +from bs4 import BeautifulSoup +from telegram import InlineKeyboardButton, InlineKeyboardMarkup +from django.template.loader import render_to_string + +def render_keyboard(template_name, context=None): + if context is None: + context = {} + html_content = render_to_string(template_name, context) + soup = BeautifulSoup(html_content, 'html.parser') + keyboard = [] + + # Если есть списки
  • , считаем их строками + rows = soup.find_all('li') + if not rows: + # Если списков нет, собираем все ссылки в одну строку + buttons = [] + for a in soup.find_all('a'): + text = a.get_text(strip=True) + callback_data = a.get('href') + buttons.append(InlineKeyboardButton(text=text, callback_data=callback_data)) + if buttons: + keyboard.append(buttons) + else: + for row in rows: + row_buttons = [] + for a in row.find_all('a'): + text = a.get_text(strip=True) + callback_data = a.get('href') + row_buttons.append(InlineKeyboardButton(text=text, callback_data=callback_data)) + if row_buttons: + keyboard.append(row_buttons) + + return InlineKeyboardMarkup(keyboard) + +def render_message(template_name, context=None): + html_content = render_to_string(template_name, context) + soup = BeautifulSoup(html_content, 'html.parser') + for tag in soup.find_all(['ul', 'li', 'a']): + tag.decompose() + return soup.get_text(separator='\n', strip=True) \ No newline at end of file diff --git a/bot/views.py b/bot/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/bot/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/config/__init__.py b/config/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/config/asgi.py b/config/asgi.py new file mode 100644 index 0000000..ffbb5f5 --- /dev/null +++ b/config/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for config project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/6.0/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings') + +application = get_asgi_application() diff --git a/config/settings.py b/config/settings.py new file mode 100644 index 0000000..78ce6c4 --- /dev/null +++ b/config/settings.py @@ -0,0 +1,90 @@ +from pathlib import Path +import os +from dotenv import load_dotenv + +# 1. Загружаем переменные из .env +load_dotenv() + +BASE_DIR = Path(__file__).resolve().parent.parent + +# 2. Настройки безопасности +SECRET_KEY = os.getenv('SECRET_KEY', 'django-insecure-default-key-if-env-missing') +DEBUG = os.getenv('DEBUG') == 'True' +ALLOWED_HOSTS = [] + +# 3. ПОДКЛЮЧЕННЫЕ ПРИЛОЖЕНИЯ (Этого не хватало!) +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'bot', +] + +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', +] + +ROOT_URLCONF = 'config.urls' + +# 4. НАСТРОЙКИ ШАБЛОНОВ (Нужны для вашего HTML-DSL) +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, # Важно: True, чтобы искать шаблоны внутри папки bot/templates + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'config.wsgi.application' + +# 5. База данных (SQLite по умолчанию) +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + +# 6. Язык и локализация (Ваши настройки) +LANGUAGE_CODE = 'ru' +TIME_ZONE = 'UTC' +USE_I18N = True +USE_TZ = True + +LANGUAGES = [ + ('ru', 'Russian'), + ('en', 'English'), + ('fr', 'French'), + ('de', 'German'), +] + +LOCALE_PATHS = [ + BASE_DIR / 'locale', +] + +STATIC_URL = 'static/' +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' + +# 7. Токен бота +TELEGRAM_TOKEN = os.getenv('TELEGRAM_TOKEN') + +# Проверка, чтобы не запускать без токена +if not TELEGRAM_TOKEN: + print("WARNING: TELEGRAM_TOKEN не найден в .env, бот не запустится!") \ No newline at end of file diff --git a/config/urls.py b/config/urls.py new file mode 100644 index 0000000..c74036a --- /dev/null +++ b/config/urls.py @@ -0,0 +1,22 @@ +""" +URL configuration for config project. + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/6.0/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path + +urlpatterns = [ + path('admin/', admin.site.urls), +] diff --git a/config/wsgi.py b/config/wsgi.py new file mode 100644 index 0000000..4ced574 --- /dev/null +++ b/config/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for config project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/6.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings') + +application = get_wsgi_application() diff --git a/locale/de/LC_MESSAGES/django.po b/locale/de/LC_MESSAGES/django.po new file mode 100644 index 0000000..054ee83 --- /dev/null +++ b/locale/de/LC_MESSAGES/django.po @@ -0,0 +1,50 @@ +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2025-12-28 23:00+0000\n" +"PO-Revision-Date: 2025-12-28 23:00+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +msgid "👤 Профиль" +msgstr "👤 Profil" + +msgid "🌐 Язык" +msgstr "🌐 Sprache" + +msgid "ℹ️ Помощь" +msgstr "ℹ️ Hilfe" + +msgid "Назад" +msgstr "Zurück" + +msgid "Вернуться в меню" +msgstr "Zurück zum Menü" + +msgid "Добро пожаловать! Выберите действие:" +msgstr "Willkommen! Wählen Sie eine Aktion:" + +msgid "Выберите язык интерфейса:" +msgstr "Wählen Sie die Sprache:" + +msgid "Главное меню" +msgstr "Hauptmenü" + +msgid "Язык сменен на Русский" +msgstr "Sprache auf Russisch geändert" + +msgid "Language changed to English" +msgstr "Sprache auf Englisch geändert" + +msgid "Язык сменен на Французский" +msgstr "Sprache auf Französisch geändert" + +msgid "Язык сменен на Немецкий" +msgstr "Sprache auf Deutsch geändert" + +msgid "Ваш профиль:\nID: {id}\nИмя: {name}" +msgstr "Ihr Profil:\nID: {id}\nName: {name}" \ No newline at end of file diff --git a/locale/en/LC_MESSAGES/django.po b/locale/en/LC_MESSAGES/django.po new file mode 100644 index 0000000..8092a84 --- /dev/null +++ b/locale/en/LC_MESSAGES/django.po @@ -0,0 +1,50 @@ +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2025-12-28 23:00+0000\n" +"PO-Revision-Date: 2025-12-28 23:00+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +msgid "👤 Профиль" +msgstr "👤 Profile" + +msgid "🌐 Язык" +msgstr "🌐 Language" + +msgid "ℹ️ Помощь" +msgstr "ℹ️ Help" + +msgid "Назад" +msgstr "Back" + +msgid "Вернуться в меню" +msgstr "Back to menu" + +msgid "Добро пожаловать! Выберите действие:" +msgstr "Welcome! Choose an action:" + +msgid "Выберите язык интерфейса:" +msgstr "Choose interface language:" + +msgid "Главное меню" +msgstr "Main menu" + +msgid "Язык сменен на Русский" +msgstr "Language changed to Russian" + +msgid "Language changed to English" +msgstr "Language changed to English" + +msgid "Язык сменен на Французский" +msgstr "Language changed to French" + +msgid "Язык сменен на Немецкий" +msgstr "Language changed to German" + +msgid "Ваш профиль:\nID: {id}\nИмя: {name}" +msgstr "Your profile:\nID: {id}\nName: {name}" \ No newline at end of file diff --git a/locale/fr/LC_MESSAGES/django.po b/locale/fr/LC_MESSAGES/django.po new file mode 100644 index 0000000..96cf61b --- /dev/null +++ b/locale/fr/LC_MESSAGES/django.po @@ -0,0 +1,50 @@ +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2025-12-28 23:00+0000\n" +"PO-Revision-Date: 2025-12-28 23:00+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +msgid "👤 Профиль" +msgstr "👤 Profil" + +msgid "🌐 Язык" +msgstr "🌐 Langue" + +msgid "ℹ️ Помощь" +msgstr "ℹ️ Aide" + +msgid "Назад" +msgstr "Retour" + +msgid "Вернуться в меню" +msgstr "Retour au menu" + +msgid "Добро пожаловать! Выберите действие:" +msgstr "Bienvenue ! Choisissez une action :" + +msgid "Выберите язык интерфейса:" +msgstr "Choisissez la langue de l'interface :" + +msgid "Главное меню" +msgstr "Menu principal" + +msgid "Язык сменен на Русский" +msgstr "Langue changée en Russe" + +msgid "Language changed to English" +msgstr "Langue changée en Anglais" + +msgid "Язык сменен на Французский" +msgstr "Langue changée en Français" + +msgid "Язык сменен на Немецкий" +msgstr "Langue changée en Allemand" + +msgid "Ваш профиль:\nID: {id}\nИмя: {name}" +msgstr "Votre profil :\nID : {id}\nNom : {name}" \ No newline at end of file diff --git a/locale/ru/LC_MESSAGES/django.po b/locale/ru/LC_MESSAGES/django.po new file mode 100644 index 0000000..fa78c67 --- /dev/null +++ b/locale/ru/LC_MESSAGES/django.po @@ -0,0 +1,50 @@ +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2025-12-28 23:00+0000\n" +"PO-Revision-Date: 2025-12-28 23:00+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +msgid "👤 Профиль" +msgstr "👤 Профиль" + +msgid "🌐 Язык" +msgstr "🌐 Язык" + +msgid "ℹ️ Помощь" +msgstr "ℹ️ Помощь" + +msgid "Назад" +msgstr "Назад" + +msgid "Вернуться в меню" +msgstr "Вернуться в меню" + +msgid "Добро пожаловать! Выберите действие:" +msgstr "Добро пожаловать! Выберите действие:" + +msgid "Выберите язык интерфейса:" +msgstr "Выберите язык интерфейса:" + +msgid "Главное меню" +msgstr "Главное меню" + +msgid "Язык сменен на Русский" +msgstr "Язык сменен на Русский" + +msgid "Language changed to English" +msgstr "Язык сменен на Английский" + +msgid "Язык сменен на Французский" +msgstr "Язык сменен на Французский" + +msgid "Язык сменен на Немецкий" +msgstr "Язык сменен на Немецкий" + +msgid "Ваш профиль:\nID: {id}\nИмя: {name}" +msgstr "Ваш профиль:\nID: {id}\nИмя: {name}" \ No newline at end of file diff --git a/manage.py b/manage.py new file mode 100644 index 0000000..8e7ac79 --- /dev/null +++ b/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main()