Skip to content

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.

Notifications You must be signed in to change notification settings

ARIBFIB/Flutter-Django-Data-Input-and-Display-Project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

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.


🐍 Testing Django Project

πŸ“ Django Data Input and Display Project

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

🌟 Features

  • 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.

πŸ“š Requirements

  • 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.


image

πŸ“‹ Overview

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.

image

image

πŸ› οΈ Getting Started

πŸ“₯ Prerequisites

Before you begin, ensure you have the following installed:

  • Python (3.6 or later)
  • pip (Python package manager)
  • Django (latest version)
  • Django REST Framework

πŸš€ Installation Steps

  1. Install Django and Django REST Framework

    pip install django djangorestframework
  2. Create a Django Project

    django-admin startproject myproject
    cd myproject
    python manage.py startapp myapp
  3. Define a Model in myapp/models.py

    from django.db import models
    
    class MyData(models.Model):
        input_text = models.CharField(max_length=255)
    
        def __str__(self):
            return self.input_text
  4. Create a Serializer in myapp/serializers.py

    from rest_framework import serializers
    from .models import MyData
    
    class MyDataSerializer(serializers.ModelSerializer):
        class Meta:
            model = MyData
            fields = ['input_text']
  5. Create an API View in myapp/views.py

    from 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)
  6. Add the URL for the API in myapp/urls.py

    from django.urls import path
    from .views import save_data
    
    urlpatterns = [
        path('save/', save_data, name='save_data'),
    ]
  7. Include the App URLs in myproject/urls.py

    from django.urls import path, include
    
    urlpatterns = [
        path('api/', include('myapp.urls')),
    ]
  8. Run Migrations

    python manage.py makemigrations
    python manage.py migrate
    python manage.py runserver

🌐 Accessing the API

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.

⚠️ Troubleshooting

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

πŸ” Checking the Database

  1. Using Django Admin

    • Create a superuser:
      python manage.py createsuperuser
    • Navigate to http://127.0.0.1:8000/admin and log in.
  2. Using Django Shell

    python manage.py shell
    from myapp.models import MyData
    MyData.objects.all()  # Lists all saved entries

πŸ“¦ Adding a Data Retrieval Endpoint

To retrieve saved data in your Flutter app:

  1. 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)
  2. Update your URL Configuration

    from django.urls import path
    from .views import MyDataList
    
    urlpatterns = [
        path('data/', MyDataList.as_view(), name='mydata_list'),
    ]

πŸ—„οΈ Optional: Admin Registration

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)

πŸ“„ Conclusion

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.

πŸ”— References


Icons Used

  • 🐍 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!

About

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.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published