3 horizontal lines, burger
3 horizontal lines, burger
3 horizontal lines, burger
3 horizontal lines, burger

3 horizontal lines, burger
Remove all
LOADING ...

Content



    Create and configure a new app for Django

    Clock
    19.07.2024
    /
    Clock
    05.10.2025
    /
    Clock
    1 minute
    An eye
    362
    Hearts
    0
    Connected dots
    0
    Connected dots
    0
    Connected dots
    0
    Tags:
    Backend
    Django

    Create a base Django project

    Before you can add a new application to your Django project, you need to create it. You can learn how to do this from this article.Once you have read this article and created your application, you can move on to the next chapter.

    Commands to create a Django app

    We will start a new app, App1.
    ./manage.py startapp App1
    In settings.py, register a new app.
    INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'App1.apps.App1Config', ]

    Commands to configure URLs

    Connect the app’s URLs to project.
    cd Project1/App1
    touch urls.py
    In a file urls.py
    from django.urls import path from .views import some urlpatterns = [ path('app/', some, name='some') ]
    In a file views.py add:
    def some(request): return render(request, 'App1/yourTemplate.html')
    Create directories in Project1/App1
    mkdir templates mkdir templates/App1
    Create an empty template.
    touch template/App1/yourTemplate.html
    Only one thing left, connect URLs in a file Project1/Project1/urls.py.
    from django.contrib import admin from django.urls import path, include urlpatterns += [ path('', include('App1.urls')), ]

    Commands to configure django model (optional)

    In a file Project1/App1/models.py, create either your own model or my testing one:
    from django.db import models class AppModel(models.Model): title = models.CharField(max_length=120) description = models.TextField() def _str_(self): return self.title
    Let’s register our model in Project1/App1/admin.py for access via the admin panel on the website.
    from django.contrib import admin from .models import AppModel class AppModelAdmin(admin.ModelAdmin): list_display = ('title', 'description') admin.site.register(AppModel, AppModelAdmin)
    Applying migrations:
    ./manage.py makemigrations ./manage.py migrate
    If you want to use default Django admin, you need to create a superuser. Jusk like that:
    ./manage.py createsuperuser

    Do not forget to share, like and leave a comment :)

    Comments

    (0)

    captcha
    Send
    LOADING ...
    It's empty now. Be the first (o゚v゚)ノ

    Other

    Similar articles


    Custom django comment and reply system, how and why

    Clock
    11.11.2023
    /
    Clock
    05.10.2025
    An eye
    650
    Hearts
    0
    Connected dots
    0
    Connected dots
    0
    Connected dots
    0
    In this article I will show how I implemented a comment system in Django on my website. This comment (reply) system is going to be available to both anonymous and …

    Implementation of authentication system on django

    Clock
    30.10.2023
    /
    Clock
    05.10.2025
    An eye
    469
    Hearts
    0
    Connected dots
    0
    Connected dots
    0
    Connected dots
    0
    Let me make a reservation right away that the authentication system that you and I will write is not based on the built-in Django application, django.contrib.auth. This will be a …

    Simple and basic Django project. How to init and what to use

    Clock
    19.07.2024
    /
    Clock
    05.10.2025
    An eye
    236
    Hearts
    0
    Connected dots
    0
    Connected dots
    0
    Connected dots
    0
    How to create an empty or very simple Django project using a virtual environment and then run a test server as a result

    Used termins


    Related questions