Thanks danjac/realworld project offer so great example.
This Project is created for Ti-Click project join PingCAP Hackathon 2022.
You can create the TiDB Cluster on TiDB Cloud which offer free TiDB Cluster.
Access Real World base Django link and open the online IDE.
Then input the /realworld/settings.py
database setting info. database name, username, password and host is necessary.
Example
DATABASES = {
"default": {
'ENGINE': 'django.db.backends.mysql',
'NAME': '${DATABASE}',
'USER': '${USERNAME}',
'PASSWORD': '${PASSWORD}',
'HOST': '${HOST}',
'PORT': '4000'
}
}
The real world don't support ONLY_FULL_GROUP_BY. So it need to be removed from TiDB global variables.
mysql> SHOW GLOBAL VARIABLES LIKE 'sql_mode';
+---------------+-------------------------------------------------------------------------------------------------------------------------------------------+
| Variable_name | Value |
+---------------+-------------------------------------------------------------------------------------------------------------------------------------------+
| sql_mode | ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
+---------------+-------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.26 sec)
mysql> SET GLOBAL sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
-> ;
Query OK, 0 rows affected (0.19 sec)
mysql> SHOW GLOBAL VARIABLES LIKE 'sql_mode';
+---------------+------------------------------------------------------------------------------------------------------------------------+
| Variable_name | Value |
+---------------+------------------------------------------------------------------------------------------------------------------------+
| sql_mode | STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
+---------------+------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.18 sec)
You can get the ip by the command below. Please add it into your TiDB Cloud security.
curl https://ipinfo.io/ip
OR You can add 0.0.0.0/0
into white list. Let all access is accepted
If you are first run this project the init is necessary by command below.
./manage.py migrate
You can start the webserver by command below.
./manage.py runserver
- https://danjacob.net/posts/anatomyofdjangohtmxproject/
- https://readthedocs.org/projects/django-conduit/downloads/pdf/latest/
danjac/realworld Readme.md
Implementation of real-world application: https://github.com/gothinkster/realworld/ using Django and HTMX.
An in-depth discussion of this implementation can be found here.
Tech Stack:
To install and run locally:
git clone https://github.com/danjac/realworld/ && cd realworld
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
./manage.py migrate && ./manage.py runserver
Note: this is just a reference implementation and is not intended for production use.