Skip to content

Adding a robots.txt file #20

@pranavnbapat

Description

@pranavnbapat

We need to add robots.txt to control web crawlers and prevent unnecessary indexing. This slightly reduces the server load caused by aggressive crawlers.

For FastAPI, in main.py

@app.get("/robots.txt", response_class=PlainTextResponse)
def robots_txt():
    return "User-agent: *\nDisallow: /"

For Django, in urls.py

def robots_txt(request):
    return HttpResponse("User-agent: *\nDisallow: /", content_type="text/plain")

urlpatterns = [
    path("robots.txt", robots_txt),
]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions