Stu Sesh with Miloo Pictures: Django Episode 15 | Produced by MENVCE

Posted by


Welcome to our tutorial on Django – Stu Sesh with Miloo Pictures [S01.E15] | Prod. MENVCE! In this tutorial, we will cover all the steps needed to create a Django project that showcases Miloo Pictures.

Before we begin, make sure you have Django installed on your machine. If not, you can install it using the following command:

pip install django

Now, let’s start by creating a new Django project. Open your terminal and run the following command:

django-admin startproject miloo_pictures

This will create a new directory called miloo_pictures with the necessary files and folders for a Django project. Navigate to this directory by running:

cd miloo_pictures

Next, let’s create a new Django app within our project. Run the following command:

python manage.py startapp pictures

This will create a new directory called pictures with the necessary files and folders for a Django app.

Now, let’s configure our project settings. Open the miloo_pictures/settings.py file and add pictures to the INSTALLED_APPS list:

INSTALLED_APPS = [
    ...
    'pictures',
]

Next, let’s define our models. Create a new file called models.py within the pictures directory and add the following code:

from django.db import models

class Picture(models.Model):
    title = models.CharField(max_length=100)
    image = models.ImageField(upload_to='images/')
    created_at = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.title

Don’t forget to run migrations to create the database tables for our models. Run the following commands:

python manage.py makemigrations
python manage.py migrate

Next, let’s create a serializer for our model. Create a new file called serializers.py within the pictures directory and add the following code:

from rest_framework import serializers
from .models import Picture

class PictureSerializer(serializers.ModelSerializer):
    class Meta:
        model = Picture
        fields = '__all__'

Now, let’s create our views. Create a new file called views.py within the pictures directory and add the following code:

from rest_framework import viewsets
from .models import Picture
from .serializers import PictureSerializer

class PictureViewSet(viewsets.ModelViewSet):
    queryset = Picture.objects.all()
    serializer_class = PictureSerializer

Finally, let’s define our URLs. Open the miloo_pictures/urls.py file and add the following code:

from django.urls import path, include
from rest_framework.routers import DefaultRouter
from pictures import views

router = DefaultRouter()
router.register(r'pictures', views.PictureViewSet)

urlpatterns = [
    path('', include(router.urls)),
]

And that’s it! You have now created a Django project that showcases Miloo Pictures. You can now run the development server by running the following command:

python manage.py runserver

Visit http://127.0.0.1:8000/pictures/ in your browser to see the list of pictures. You can also use tools like Postman to test your API endpoints.

I hope you found this tutorial helpful. Happy coding!

0 0 votes
Article Rating

Leave a Reply

43 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@StudioSESH
18 days ago

Street Sesh Ep1 Out Now: https://www.youtube.com/watch?v=QTCpOwSCZF8

@nicjanssen7275
18 days ago

Kim+NiC❤❤💍💍🫶🏻💋

@hubertnicpon6191
18 days ago

Boah ist das scheisse

@DiarAbdulhamid
18 days ago

Jemand 2025 hier?

@DiarAbdulhamid
18 days ago

Jemand 2087 hier!

@DiarAbdulhamid
18 days ago

Jemand 2025 hier ?

@user-cm8uq5bh6w
18 days ago

Mann, bruder, bester Mann

@Hasan_12_
18 days ago

Muss nicht

@jamesherold4410
18 days ago

Was Geht jemand aus 2024

@PhilippSchafer-tw4gw
18 days ago

wie gross ist django

@HamburgSOS-lq9qi
18 days ago

Ja

@Devranoran4747
18 days ago

Ich

@gabigabi5508
18 days ago

Einfach schon 2 Jahre alt

@YasinElsayed-zh5rw
18 days ago

geile rap wow uhr geil

@user-ot6on9fl4l
18 days ago

Ja ich

@aquex4720
18 days ago

2024 und immer noch da Django auf die 1

@deniel-mauriceseifert-ys9eo
18 days ago

Jemanden 2024 hir

@LL-fy3cf
18 days ago

Mehr davon bitte

@zycuCW
18 days ago

Video ist geisteskrank

@user-ef9eu5io6d
18 days ago

Ist noch jemand da😊

43
0
Would love your thoughts, please comment.x
()
x