static

How to add custom headers to static files in fastapi

How to add custom headers to static files in fastapi Question: We are using the following method to mount the static files from a directory app.mount("/static", StaticFiles(directory="static"), name="static") We have sent a custom headers for api for security related steps using a common method before sending response to the client. Is there a way to …

Total answers: 1

How to have typing support for a static property (using a decorator)

How to have typing support for a static property (using a decorator) Question: Given a static property decorator: class static_property: def __init__(self, getter): self.__getter = getter def __get__(self, obj, objtype): return self.__getter(objtype) @staticmethod def __call__(getter_fn): return static_property(getter_fn) That is applied to a class as follows: class Foo: @static_prop def bar(self) -> int: return 10 Add …

Total answers: 1

Staticfiles not loading on Django

Staticfiles not loading on Django Question: My static files are not loading on Django. I’m running this on my local machine. The location of example.png is main/static/main/example.png. main is an app. Here’s my settings.py: """ Django settings for tutorials project. Generated by ‘django-admin startproject’ using Django 4.1.1. For more information on this file, see https://docs.djangoproject.com/en/4.1/topics/settings/ …

Total answers: 2

When should a static method be a function?

When should a static method be a function? Question: I am writing a class for an image processing algorithm which has some methods, and notably a few static methods. My IDE keeps telling me to convert static methods to function which leads me to the following question: When should a static method be turned into …

Total answers: 1

Stylesheet url_for code for image in a parallel folder

Stylesheet url_for code for image in a parallel folder Question: I am attempting to build a website using Flask. I am using Python 3.9 I have the following directory tree: environment/ main.py app.yaml requirements.txt Templates/ base.html #base template index.html #extends base.html Static/ css/ main.css images/ favicon.ico bckgrnd.jpg fonts/ Carolingian.ttf Latin.ttf Here is the code in …

Total answers: 1

Python local variables statically determined?

Python local variables statically determined? Question: Python tutorial says that (https://docs.python.org/3/tutorial/classes.html#python-scopes-and-namespaces) In fact, local variables are already determined statically. How to understand this? Based on what I knew static means that the type of a variable is determined at compile time. But it is not true considering for example x = 1 x = ‘str’ …

Total answers: 3

ValueError: Missing staticfiles manifest entry for 'favicon.ico'

ValueError: Missing staticfiles manifest entry for 'favicon.ico' Question: I’m getting a ValueError when running python manage.py test. My project is named fellow_go, and I’m currently working on an App called pickup. Please note that this error is added in a relatively recent commit to Django: Fixed #24452 — Fixed HashedFilesMixin correctness with nested paths.. ====================================================================== …

Total answers: 15

Do we really need @staticmethod decorator in python to declare static method

Do we really need @staticmethod decorator in python to declare static method Question: I am curious about why we need the @staticmethod decorator to declare method as static. I was reading about static methods in Python, and I came to know that static method can be callable without instantiating its class. So I tried the …

Total answers: 5