-
I made everything on MacOS, in PyCharm, with Python 3.12.3.
-
I just wanted to make a simple example of how to use Django with Telegram WebApp. My code is not perfect, but it works :D and remember that this is just an example :)
- Download repository tp your local machine
- Download and install Pyenv (optional, but I use it to manage Python versions)
- Download and install
Python 3.12.3
- Download and install PyCharm (optional, but I do everything in it)
- Install ruff to your global python (
pip install ruff==0.4.4
) (optional, but I use it to format code) - Create virtual environment to your project and activate it
- Run
setup.sh
to install requirements, generateDJANGO_SECRET_KEY
and make migrations - Run ngrok (
run_ngrok_server.sh
) - Add the url to the
ALLOWED_HOSTS
(without https) andCSRF_TRUSTED_ORIGINS
(with http) in thesettings.py
file of the Django project - Set up the ngrok url in the WebApp settings in Telegram (BotFather)
- Run
run_django_server.sh
to start the server
- Create a bot in Telegram (BotFather)
- Create a WebApp in Telegram (BotFather)
- Set up ngrok and run it (
run_ngrok_server.sh
) - Set up url for WebApp in Telegram (BotFather)
- Download ngrok (
brew install ngrok
) - Run ngrok (
run_ngrok_server.sh
)
In PyCharm, you can set up formatters to be automatically applied to changed files when saving.
- Setting an alias for
ruff
:
- In the
~/.bashrc
/~/.zshrc
file or in the windows env, add env variables forruff
:
export ruff="/Users/user_name/.pyenv/versions/3.12.3/bin/ruff" # specify your full path
-
Setting in
File Watcher
(Preferences
->Tools
->File Watchers
):Ruff check
settings:File type: Any Scope: python Program: ruff Argument: check --config $ProjectFileDir$/pyproject.toml $FilePath$ OutPut paths to refresh: $FilePath$ Working directory: $ProjectFileDir$ Show console: On Error All checkboxes should be empty.
Ruff format
settings (same as inRuff check
exceptArgument
):File type: Python Scope: python Program: ruff Argument: format --config $ProjectFileDir$/pyproject.toml $FilePath$ OutPut paths to refresh: $FilePath$ Working directory: $ProjectFileDir$ Show console: On Error All checkboxes should be empty.