April 10, 20232 minutes
Pynecone ์์ํ๊ธฐ
ํน์ง (๊ณต์ ์ฌ์ดํธ https://pynecone.io/ ์์ ๋งํ๋โฆ)
pip๋ฅผ ํตํด ์ค์น
pip install pynecone-io
๋ชจ๋ Pynecone function, class๋ pc.
์ ๋์ฌ๋ก ์์!
pc init : Initialize a template app in new directory
์์ ๊ฐ์ด ๊ธฐ๋ณธ ํ ํ๋ฆฟ์ ์์ฑํด์ค
directory structure
MY_FIRST_PYNECONE_APP
โโโ .web
โโโ assets
โโโ my_first_pynecone_app
โ โโโ __init__.py
โ โโโ my_first_pynecone_app.py
โโโ pcconfig.py
.web
NextJS ์ฑ์ผ๋ก ์ปดํ์ผ ๋ค์ด๋์ด์ .web
๋๋ ํ ๋ฆฌ์ ์ ์ฅ๋จ
ํด๋น ๋๋ ํ ๋ฆฌ ์ ๋ ํ์ ์์ง๋ง, ๋๋ฒ๊น
์ ์ ์ฉํจ
๊ฐ๊ฐ์ Pynecone ํ์ด์ง๋ .js ํ์ผ๋ก ์ปดํ์ผ๋์ด์ .web/pages
๋๋ ํฐ๋ก๋ฆฌ์ ์ ์ฅ๋จ
assets
favicon , ํฐํธ, ์ด๋ฏธ์ง ๋ฑ๊ณผ ๊ฐ์ asset๋ค์ ์ ์ฅํ๋ ๋๋ ํ ๋ฆฌ
assets/image.png
๋ก image๋ฅผ ํด๋น ๋๋ ํ ๋ฆฌ์ ์ ์ฅํ๋ฉด, ์๋์ ๊ฐ์ด ํด๋น ์ด๋ฏธ์ง๋ฅผ ๋์คํ๋ ์ดํ ์ ์์.
pc.image(src="image.png")
Main Project : {my_first_pynecone_app}/{my_first_pynecone_app.py}
pc init ํ๋ฉด, ํด๋น ๋๋ ํ ๋ฆฌ ์ด๋ฆ๊ณผ ๊ฐ์ ์ด๋ฆ์ app (๋๋ ํ ๋ฆฌ์ด๋ฆ.py) ๋ฅผ ์์ฑํด์ค.
Configuration : **pcconfig.py
**
app์ ๊ดํ configuration ๊ดํ ํ์ผ์.
์๋์ ๊ฐ์ด default๋ก ์์ฑ๋จ
import pynecone as pc
config = pc.Config(
app_name="my_first_pynecone_app",
db_url="sqlite:///pynecone.db",
env=pc.Env.DEV,
)
pc run
my_first__pynecone_app.py
"""Welcome to Pynecone! This file outlines the steps to create a basic app."""
from pcconfig import config
import pynecone as pc
docs_url = "https://pynecone.io/docs/getting-started/introduction"
filename = f"{config.app_name}/{config.app_name}.py"
# State๋ ๋ชจ๋ variable๋ค (**vars**)์ ์ ์
class State(pc.State):
"""The app state."""
pass
# Frontend
def index():
return pc.center(
pc.vstack(
**pc.heading**("Welcome to Pynecone!", font_size="2em"),
**pc.box**("Get started by editing ", pc.code(filename, font_size="1em")),
**pc.link**(
"Check out our docs!",
href=docs_url,
border="0.1em solid",
padding="0.5em",
border_radius="0.5em",
_hover={
"color": "rgb(107,99,246)",
},
),
spacing="1.5em",
font_size="2em",
),
padding_top="10%",
)
# Routing
# Add state and page to the app.
app = pc.App(state=State)
app.add_page(index)
# Compiling
app.compile()
pc.heading(), pc.box() pc.link() ๊ณผ ๊ฐ์ 50๊ฐ ์ด์์ built-in components ์์
ํ๋ก ํธ์๋, ๋ฐฑ์๋ ๋ชจ๋ ํด๊ฒฐํจ.