Py2exe for Python 3.0

Update 2014-05-15 py2exe for Python 3.x is now released! Get it on PyPI. Old information Have a look at the py2exe SourceForge project SVN repository at: http://py2exe.svn.sourceforge.net/ The last I looked at it, it said the last update was August 2009. But keep an eye on that to see if there’s any Python 3 work … Read more

Detect mobile devices with Django and Python 3

Django User Agents package is compatible with Python 3. Follow the installation instructions in the link provided above and then you can use it as follows: def my_view(request): # Let’s assume that the visitor uses an iPhone… request.user_agent.is_mobile # returns True request.user_agent.is_tablet # returns False request.user_agent.is_touch_capable # returns True request.user_agent.is_pc # returns False request.user_agent.is_bot # … Read more

How to create routes with FastAPI within a class

This can be done by using an APIRouter‘s add_api_route method: from fastapi import FastAPI, APIRouter class Hello: def __init__(self, name: str): self.name = name self.router = APIRouter() self.router.add_api_route(“/hello”, self.hello, methods=[“GET”]) def hello(self): return {“Hello”: self.name} app = FastAPI() hello = Hello(“World”) app.include_router(hello.router) Example: $ curl 127.0.0.1:5000/hello {“Hello”:”World”} add_api_route‘s second argument (endpoint) has type Callable[…, Any], … Read more

Django TypeError: argument of type ‘PosixPath’ is not iterable

Make sure that you imported os in project-level settings.py: import os Add following in DATABASES within settings.py: ‘NAME’: os.path.join(BASE_DIR, ‘db.sqlite3’), In last versions of django, we can do the following settings using str(): DATABASES = { ‘default’: { ‘ENGINE’: ‘django.db.backends.sqlite3’, ‘NAME’: str(BASE_DIR / “db.sqlite3”), } }