Django-uvicorn.md

django ํ”„๋กœ์ ํŠธ๋ฅผ ์‹คํ–‰ ํ• ๋•Œ์—๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ manage.py๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœํ•˜๋Š”

$ python manage.py runserver

์œ„ ๋ช…๋ น์–ด๋กœ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

ํ•˜์ง€๋งŒ ์‹ค์ œ ๋ฐฐํฌ๋ฅผํ•  ๋•Œ์—๋Š” ๋Œ€๋ถ€๋ถ„ WAS + wsgi๋ฅผ ์„ž๋Š” ๋ฐฉ์‹์œผ๋กœ ์„œ๋ฒ„๋ฅผ ์‹คํ–‰์‹œํ‚ต๋‹ˆ๋‹ค.

์ด ์ด์œ ์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๋˜ ์ค‘ ๋ณธ ํฌ์ŠคํŠธ์—์„œ runserver์— ๋Œ€ํ•ด ์ž˜ ์„ค๋ช…ํ•˜๋Š” ํฌ์ŠคํŒ…์ด ์žˆ์–ด ๊ณต์œ ํ•˜๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

(https://twowix.me/85)

๊ธ€์˜ ๋‚ด์šฉ์„ ์š”์•ฝํ•ด๋ณด์ž๋ฉด

  1. python manage.py runserver ์‹คํ–‰

  2. manage.py

    • Import Error

    • execute_from_command_line(sys.argv)

  3. execute_from_command_line(argv)

    • utility = ManagementUtility(argv)

    • utility.execute()

  4. ManagementUtility

    • __init__() : argv ์„ธํŒ…

    • execute()

      • subcommand = self.args or subcommand = help

    • CommandParser : ๋‘๋ฒˆ์งธ ์ธ์ž๊ฐ’, ์ฆ‰ ์˜ต์…˜ ์ฒดํฌ

    • fetch_command(subcommand).run_from_argv(self.argv)

  5. run_from_args

    • ์ •์ ํŒŒ์ผ ์ฒดํฌ

    • DB ์ฒดํฌ

    • ๋กœ๊น… ์„ค์ •

    • runserver ์‹คํ–‰

  6. django/core/management/commands/runserver.py

    • inner_run

      • ์„œ๋ฒ„ ์ข…๋ฃŒ ์ปค๋งจ๋“œ ์…‹ํŒ…

      • ๋งˆ์ด๊ทธ๋ ˆ์ด์…˜ ์ฒดํฌ

      • ์„œ๋ฒ„ ์‹คํ–‰ ๋ฐ ์…‹ํŒ… ๋„์šฐ๊ธฐ

      • run()

    • run

      • django.core.servers.basehttp: python ๊ธฐ๋ณธ http server ์—ด๊ธฐ

์œ„์™€ ๊ฐ™์€ ๊ณผ์ •์œผ๋กœ runserver ๊ฐ€ ์‹คํ–‰๋˜๊ฒŒ ๋˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

์—ฌ๊ธฐ์„œ ์–ด๋–ค ๋ถ€๋ถ„ ๋•Œ๋ฌธ์— runserver๋ฅผ ์‹ค ์„œ๋น„์Šค ๋ฐฐํฌ์‹œ์— ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๊ฐ€ ๋ผ๊ณ  ํ•œ๋‹ค๋ฉด ๋งจ ๋งˆ์ง€๋ง‰์— ์‹คํ–‰๋˜๋Š” django.core.servers.basehttp ๋ฅผ ์‚ฌ์šฉํ•ด ์„œ๋ฒ„๋ฅผ ์—ด๊ธฐ ๋•Œ๋ฌธ์ด๋ผ๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.

ํ•ด๋‹น ๋ชจ๋“ˆ์„ ์ž˜ ๋ณด๋ฉด ์œ„์˜ ์ฃผ์„ ์ฒ˜๋ฆฌ๋œ๊ณณ์— This is a simple server for use in testing or debugging Django apps. it hasn't been reviewed for security issues. DON'T USE IT FOR PRODUCTION USE! ๋ผ๊ณ  ์“ฐ์—ฌ์žˆ์Šต๋‹ˆ๋‹ค.

๊ฐ„๋‹จํ•˜๊ฒŒ ํ•ด์„ํ•˜๋ฉด

์ด ์„œ๋ฒ„๋Š” ๊ฐ„๋‹จํ•œ ํ…Œ์ŠคํŠธ๋‚˜ ๋””๋ฒ„๊น…์šฉ์œผ๋กœ ์‚ฌ์šฉ๋˜๋Š”๊ฒƒ์ด๋‹ˆ, ์ ˆ๋Œ€ ๋ฐฐํฌ์šฉ์œผ๋กœ ์‚ฌ์šฉํ•˜์ง€ ๋ง์•„๋ผ!

๋ผ๊ณ  ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ด ๋ชจ๋“ˆ์„ ๋” ์ž˜ ๋ณด๋ฉด https๋ฅผ ์‚ฌ์šฉํ•˜๊ฒŒ ๋˜๋ฉด ์˜ˆ์™ธ์ฒ˜๋ฆฌ ํ•˜๋Š” ๋‹จ๊ณ„๋„ ์กด์žฌํ•ฉ๋‹ˆ๋‹ค. ์ด๋งŒํผ ์„œ๋ฒ„์˜ ๋ณด์•ˆ๋ฌธ์ œ๊ฐ€ ์žˆ๋‹ค๊ณ  ํŒ๋‹จํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ด์™€ ๊ฐ™์€ ์ด์œ ๋•Œ๋ฌธ์— ์‹ค์ œ ๋ฐฐํฌ์‹œ์—๋Š” gunicorn, uvicorn ๊ณผ ๊ฐ™์€ WAS๋ฅผ ๊ฐ™์ด ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ •ํ™•ํ•œ ์‚ฌ์šฉ๋ฐฉ๋ฒ•์€ ๋‹ค๋ฅธ ๊ณณ์„ ์ฐพ์•„๋ณด์‹œ๋Š”๊ฒŒ ์ข‹๊ณ  ๊ฐ„๋‹จํ•œ ์‹คํ–‰๋ช…๋ น์–ด ์ •๋„๋งŒ ๊ธฐ๋กํ•˜๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

gunicorn [asgi.py ๋“ค์–ด์žˆ๋Š” ํด๋” ์ด๋ฆ„].asgi:application --bind [IP]:[PORT] -k uvicorn.workers.UvicornWorker

์œ„์˜ ๋ช…๋ น์–ด๋Š” uvicorn์„ ์‚ฌ์šฉํ•˜์—ฌ ๋น„๋™๊ธฐ์ฒ˜๋ฆฌ๊ฐ€ ๊ฐ€๋Šฅํ•˜๊ฒŒ๋” ์„œ๋ฒ„๋ฅผ ์‹คํ–‰ํ•˜๋Š” ๋ช…๋ น์–ด์ž…๋‹ˆ๋‹ค.

Last updated