Hereβs a structured description for your GitHub repository, complete with icons, bullet points, and a detailed explanation. You can customize it further if needed.
This project is a simple Django web application that allows users to input data through a form, save it to a database, and view it in the Django admin panel. This guide will walk you through the steps of setting up your own project based on this implementation.
DjangoFlutterTesting.mp4
- User Input Form: A user-friendly form for data entry.
- Data Storage: Saves the entered data in a SQLite database.
- Admin Interface: View and manage data easily using Django's built-in admin panel.
- Python 3.x
- Django
- SQLite (default database)
Here's a structured and detailed description for your GitHub repository that outlines the setup and implementation of your Django project. This format includes proper headings, bullet points, icons, and clear instructions to help other users understand and implement the project.
This repository contains a simple Django project that demonstrates how to create a RESTful API for saving and retrieving data using Django and Django REST Framework.
Before you begin, ensure you have the following installed:
- Python (3.6 or later)
- pip (Python package manager)
- Django (latest version)
- Django REST Framework
-
Install Django and Django REST Framework
pip install django djangorestframework
-
Create a Django Project
django-admin startproject myproject cd myproject python manage.py startapp myapp -
Define a Model in
myapp/models.pyfrom django.db import models class MyData(models.Model): input_text = models.CharField(max_length=255) def __str__(self): return self.input_text
-
Create a Serializer in
myapp/serializers.pyfrom rest_framework import serializers from .models import MyData class MyDataSerializer(serializers.ModelSerializer): class Meta: model = MyData fields = ['input_text']
-
Create an API View in
myapp/views.pyfrom rest_framework import status from rest_framework.decorators import api_view from rest_framework.response import Response from .models import MyData from .serializers import MyDataSerializer @api_view(['POST']) def save_data(request): if request.method == 'POST': serializer = MyDataSerializer(data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
-
Add the URL for the API in
myapp/urls.pyfrom django.urls import path from .views import save_data urlpatterns = [ path('save/', save_data, name='save_data'), ]
-
Include the App URLs in
myproject/urls.pyfrom django.urls import path, include urlpatterns = [ path('api/', include('myapp.urls')), ]
-
Run Migrations
python manage.py makemigrations python manage.py migrate python manage.py runserver
Your Django API is now ready to accept POST requests at http://127.0.0.1:8000/api/save/ to save data in the database.
If you encounter issues:
- Install CORS headers:
pip install django-cors-headers
- Update your
settings.py:INSTALLED_APPS = [ ... 'corsheaders', ] MIDDLEWARE = [ 'corsheaders.middleware.CorsMiddleware', ... ] CORS_ALLOW_ALL_ORIGINS = True
-
Using Django Admin
- Create a superuser:
python manage.py createsuperuser
- Navigate to
http://127.0.0.1:8000/adminand log in.
- Create a superuser:
-
Using Django Shell
python manage.py shell from myapp.models import MyData MyData.objects.all() # Lists all saved entries
To retrieve saved data in your Flutter app:
-
Create a GET Endpoint in your Django API:
from rest_framework.views import APIView from rest_framework.response import Response from .models import MyData from .serializers import MyDataSerializer class MyDataList(APIView): def get(self, request): texts = MyData.objects.all() serializer = MyDataSerializer(texts, many=True) return Response(serializer.data)
-
Update your URL Configuration
from django.urls import path from .views import MyDataList urlpatterns = [ path('data/', MyDataList.as_view(), name='mydata_list'), ]
To view your model in the Django admin:
- Open
myapp/admin.py:from django.contrib import admin from .models import MyData admin.site.register(MyData)
This project demonstrates how to create a basic Django API to save and retrieve data. You can build upon this foundation to create more complex applications.
- π Python
- π Overview
- π₯ Prerequisites
- π Installation Steps
- π Accessing the API
β οΈ Troubleshooting- π Checking the Database
- π¦ Adding a Data Retrieval Endpoint
- ποΈ Optional: Admin Registration
- π Conclusion
- π References
Feel free to customize this structure as needed!


