Jahan is a straightforward WSGI framework designed to facilitate the development of web applications in Python. Its core components, including Request, Response, and Router objects, simplify the management of HTTP requests and responses, offering developers a clear structure and easy-to-use methods for building web solutions.
Jahan is a straightforward Web Server Gateway Interface (WSGI) framework designed to provide a foundational structure for developing web applications in Python. With its essential components, Jahan enables developers to handle HTTP requests efficiently and generate appropriate responses.
Request object that encapsulates WSGI environment dictionaries, offering straightforward access to request properties such as query parameters and request methods.Response class simplifies the creation of HTTP responses, allowing developers to set status codes, content types, and response headers effortlessly.Router object that facilitates URL routing, making it easy to map incoming requests to defined callback functions.To utilize the Jahan framework:
Jahan class and configure your application's routes using the add_route method.run() method, which makes it available at http://127.0.0.1:8000/ for testing in your web browser.Here's a minimal implementation of a Jahan application:
from jahan.jahan import Response, Jahan
app = Jahan()
@app.add_route(r'/$')
def index(request):
return Response('Hello world')
if __name__ == "__main__":
app.run()
In this example, a simple "Hello world" application is defined and served.
Jahan also supports rendering templates using TemplateResponse, making it easy to employ Jinja2 templating in your web responses:
TemplateResponse("template.html", context={"Name": "John"})
In the associated HTML file, data can be presented as:
<p>{{ Name }}</p>
Jahan includes the WSGIServer class, which acts as a simple WSGI server to host web applications on your local machine. This is ideal for development and testing purposes. Key functionalities include:
Start by creating an instance of the WSGIServer class, passing your Jahan application:
server = WSGIServer('127.0.0.1', 8000, Jahan('MyApp').application)
server.serve_forever()
This serves the application at http://127.0.0.1:8000/.
Jahan is primarily intended for educational purposes, demonstrating the fundamental principles underlying web frameworks. Its security protocols and error handling are not fully developed; therefore, it is not recommended for deployment in a production environment.
For a live demonstration, please visit the demo application created using Jahan and SQLAlchemy. To dive deeper into the functionalities of Jahan, refer to the repository for additional documentation and examples.
No comments yet.
Sign in to be the first to comment.