About RequestFactory in Django Tests

In Django tests, when using RequestFactory to create fake requests, you can include extra META parameters by passing them as keyword arguments to methods like get() and post().

For example to pass a custom user agent you would do this:

factory = RequestFactory()
request = factory.get(
    "/", 
    {"page": "1"}, 
    HTTP_USER_AGENT="Facebot",
)

Tips and Tricks Programming Testing Django 5.x Django 4.2 Django 3.2