Skip to main content

A Django app for automating RESTful API development using Django Rest Framework (DRF), simplifying CRUD operations for Django models.

Project description

drfapigenerator

DRF API Generator simplifies API development in Django projects by automating the creation of RESTful APIs using Django Rest Framework (DRF). It generates necessary components such as viewsets, serializers, and routing based on your Django models, allowing developers to quickly expose CRUD (Create, Read, Update, Delete) operations via API endpoints. This tool enhances productivity by reducing manual configuration and boilerplate code, making it easier to build and maintain APIs in Django applications.

Installation

add drfapigenerator in settings.py installed app.

INSTALLED_APPS = [
 -------------------
    'drfapigenerator',
 -------------------
]

generate automatic api's for your all models of your app.

python manage.py makeapi --app <your_app_name>

Usage/Examples

To generate APIs for a specific Django app

Run the following management command, replacing <your_app_name> with the name of your Django app:

python manage.py makeapi --app <your_app_name>

This command will automatically create necessary viewsets, serializers, and API routing for all models in the specified app.

you can see the generated API endpoints at http://localhost:8000/api/

Example:

Suppose you have a Django app named myapp with a model MyModel defined as follows:

myapp/models.py

from django.db import models

class MyModel(models.Model):
    name = models.CharField(max_length=100)
    description = models.TextField()

    def __str__(self):
        return self.name

After running:

python manage.py makeapi --app myapp

You can access the API for MyModel at http://localhost:8000/api/mymodel/.

This structure provides clear instructions on how to install and use DRF API Generator in your Django project, including a practical example for generating APIs.

Warning: Correcting the URL Configuration

In the current setup, there may be an issue with the registration of the accounts router. Ensure that your urlpatterns in your urls.py file are correctly configured as follows:

Incorrect Configuration

The following code may lead to issues:

urlpatterns = [
    path('admin/', admin.site.urls),
   
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

#*********This is accounts router registered by autoapi*********
from accounts.routers.routers import router as accounts_router 
urlpatterns.append(path('api/',include(accounts_router.urls)))

Correct Configuration

Replace the above code with the following corrected configuration:

Ensure you import the accounts_router correctly:

#*********This is accounts router registered by autoapi*********
from accounts.routers.routers import router as accounts_router
urlpatterns = [
    path('admin/', admin.site.urls),
    path('api/', include(accounts_router.urls)),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

GitHub Repository

The source code for DRF API Generator is available on GitHub.

About the Author

Manoj Das
Senior Python Developer at Vrit Technologies 5 years of experience

LinkedIn: Manoj Das

License

MIT

MIT License

Copyright (c) [2024] [Manoj Kumar Das]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

drfapigenerator-4.5.0.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

drfapigenerator-4.5.0-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

Details for the file drfapigenerator-4.5.0.tar.gz.

File metadata

  • Download URL: drfapigenerator-4.5.0.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.0

File hashes

Hashes for drfapigenerator-4.5.0.tar.gz
Algorithm Hash digest
SHA256 52ec89a256c96886cc8a9b2dbc680dea535f13daecf189abc759e46cddb341c7
MD5 bc03215d0e8e8534e17926487b996730
BLAKE2b-256 1f2cbf53a40a824e5792a4b4bcb42a1ee1d889ea9c496cfedb8cba467fad0e2e

See more details on using hashes here.

File details

Details for the file drfapigenerator-4.5.0-py3-none-any.whl.

File metadata

File hashes

Hashes for drfapigenerator-4.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d34f733c6096464781e7b382c9da377f785b45bd8130056a0f5855cfd149e095
MD5 a59a1405a9dbc3cf5a4bd742cd1df245
BLAKE2b-256 e216fb2ae4b62b04a0282db5695d673012a2b554acf0b482353c5ceff5947cac

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page