Giter VIP home page Giter VIP logo

Comments (9)

andreaslongo avatar andreaslongo commented on July 22, 2024 1

A quick workaround would be to call global_init() before any views import.

From ./code/ch8-async-databases/main.py:

from pathlib import Path

import fastapi
import fastapi_chameleon
import uvicorn
from starlette.staticfiles import StaticFiles

from data import db_session

fastapi_chameleon.global_init('templates', auto_reload=True)

from views import account
from views import home
from views import packages

Note the auto_reload=True argument which set to dev_mode variable in the origin call.

from web-applications-with-fastapi-course.

prcutler avatar prcutler commented on July 22, 2024

This looks really similar to the error I'm getting and I'm going to talk to Michael in office hours today in about 30 minutes.

This line in particular matches an error I'm getting:
File "/home/cristiana/anaconda3/envs/fastapi/lib/python3.9/posixpath.py", line 76, in join a = os.fspath(a)

I also see:

File "/Users/prcutler/workspace/silversaucer/testvenv/lib/python3.9/site-packages/fastapi_chameleon/engine.py", line 71, in response_inner
    if not os.path.exists(os.path.join(template_path, template_file)):
  File "/usr/local/Cellar/[email protected]/3.9.2_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/posixpath.py", line 76, in join
    a = os.fspath(a)

I have a bug open in my repo at prcutler/silversaucer#317 and if I find an answer, I'll post here as well.

from web-applications-with-fastapi-course.

Cristianasp avatar Cristianasp commented on July 22, 2024

Hello @prcutler , the error seams to be in engine.py (fastapi-chameleon). It is calling os.path.join with a parameter with None (template_path).

I have made a temporary solution in the following function, to be able to run the code.

Yet, I havent figured out where template_path should be declared in order to make this works ;-)

    def response_inner(f):
        nonlocal template_file

        if not template_file:
            # Use the default naming scheme: template_folder/module_name/function_name.pt
            module = f.__module__
            if '.' in module:
                module = module.split('.')[-1]
            view = f.__name__
            template_file = f'{module}/{view}.html'

            if template_path is not None:
                if not os.path.exists(os.path.join(template_path, template_file)):
                    template_file = f'{module}/{view}.pt'
            else:
                template_file = f'{module}/{view}.pt'

from web-applications-with-fastapi-course.

prcutler avatar prcutler commented on July 22, 2024

This should be fixed as Michael released a new version.

Just run:

pip install git+https://github.com/mikeckennedy/fastapi-chameleon again

from web-applications-with-fastapi-course.

Cristianasp avatar Cristianasp commented on July 22, 2024

This should be fixed as Michael released a new version.

Just run:

pip install git+https://github.com/mikeckennedy/fastapi-chameleon again

I believe not, since I installed the package today.

from web-applications-with-fastapi-course.

prcutler avatar prcutler commented on July 22, 2024

He released a new version after these bug reports and it did fix it for me. Make sure you're using fastapi_chameleon-0.1.7 and not 0.1.6

See: mikeckennedy/fastapi-chameleon#7

from web-applications-with-fastapi-course.

andreaslongo avatar andreaslongo commented on July 22, 2024

fastapi-chameleon-0.1.7 fixed it for me too.

Thanks @prcutler and @mikeckennedy

from web-applications-with-fastapi-course.

mikeckennedy avatar mikeckennedy commented on July 22, 2024

Glad you all got it working. Sorry for the trouble.

from web-applications-with-fastapi-course.

Cristianasp avatar Cristianasp commented on July 22, 2024

Cool ! Thank you !

from web-applications-with-fastapi-course.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.