DEV Community

Cover image for Building Blog with Bocadillo - Project Structure
Itachi Uchiha
Itachi Uchiha

Posted on • Updated on

Building Blog with Bocadillo - Project Structure

GitHub Repository for this series: https://github.com/aligoren/bocadillo_blog


Project Structure

We'll do some of the changes in our project. Firstly, we'll create a folder called blog. So, this folder will contain our project files.

Using this kind of structure, we can separate our projects. You can use any name for your project folder.

After that, we will move the app.py file into that folder.

ASGI File

We'll create a file called asgi.py under the root folder.

It will be like that;

from bocadillo import configure
from blog.app import app

configure(app)
Enter fullscreen mode Exit fullscreen mode

app.py File

We don't need to call configure method again inside this file. Because we called it in the asgi.py file. Let's change blog/app.py file.

from bocadillo import App

app = App()

@app.route("/")
async def index(req, res):
    res.text = "Hello World!"
Enter fullscreen mode Exit fullscreen mode

We just removed configure method. Now we can run our project like that;

uvicorn asgi:app --reload
Enter fullscreen mode Exit fullscreen mode

Now it is more elegant :) I think this is very important because you don't want to put everything in one file. Nobody wants. Everything could be more complex in large projects.

The next thing will be about settings.

Top comments (0)