Django: Cómo dominarlo en solo 5 minutos

Posted by


Django is a web framework for building web applications in Python. It provides a robust set of tools and features to help developers create secure and scalable web applications quickly and efficiently. In this tutorial, I will show you how to set up a basic Django project in just 5 minutes.

Step 1: Install Django
First, you will need to install Django. You can do this using pip, the Python package installer. Open your terminal and run the following command:

pip install django

This will install the latest version of Django on your system.

Step 2: Create a new Django project
Next, you will need to create a new Django project. Navigate to the directory where you want to create your project and run the following command:

django-admin startproject myproject

This will create a new directory called ‘myproject’ which will contain the basic structure for your Django project.

Step 3: Run the Django development server
Once your project is created, navigate to the project directory and run the following command to start the Django development server:

cd myproject
python manage.py runserver

This will start the server and you should see a message indicating that the server is running. You can now access your Django project by opening a web browser and navigating to http://127.0.0.1:8000/.

Step 4: Create a Django app
In Django, a web application is made up of one or more apps. To create a new app in your Django project, run the following command:

python manage.py startapp myapp

This will create a new directory called ‘myapp’ which will contain the basic structure for your Django app.

Step 5: Define a URL route and view
To create a simple view in your Django app, open the ‘views.py’ file in the ‘myapp’ directory and define a function that will return a response. For example:

from django.http import HttpResponse

def home(request):
    return HttpResponse("Hello, Django!")

Next, open the ‘urls.py’ file in the ‘myapp’ directory and define a URL route that will map a URL to your view. For example:

from django.urls import path
from . import views

urlpatterns = [
    path('', views.home, name='home'),
]

Finally, open the ‘urls.py’ file in the ‘myproject’ directory and include the URL route from your Django app. For example:

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('myapp.urls')),
]

Now, when you navigate to http://127.0.0.1:8000/ in your web browser, you should see the message "Hello, Django!" displayed on the page.

That’s it! In just 5 minutes, you have set up a basic Django project with a simple view. Django provides a ton of features and functionality to help you build more complex web applications, so be sure to check out the Django documentation for more information.

0 0 votes
Article Rating

Leave a Reply

8 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@alejandrovelasquezgoytia2076
9 days ago

Sirve para crear paginas web???

@ronalchenco
9 days ago

demasiadas cosas por setear en un simple hola mundo, no creen ?

@orye7462
9 days ago

No sé pero la rola de fondo y el contenido del video super bueno!!!!

@bastianmartinez582
9 days ago

muy tecnico no entendi el inicio ya me marie ajjaj pero gracias igual saludos

@FiliusDeiPatris
9 days ago

Quien en su sano juicio podría pensar que es una buena idea devolver plantillas html en una app de servidor como djang ??

@THEsyntheticFresh
9 days ago

Después de un curso bastante denso y querer hacer mi app con la documentación como guía, creo que este es el tutorial perfecto para completar mis proyectos. Mil gracias, me suscribo.

@liudmilapalomino2246
9 days ago

Acabo de aprender mas que un video de 2 horas, aqui ya pude entender alfin como es que se relacionan los archivos urls views y el otro urls

@alexprado7903
9 days ago

Tu curso de Vue es simplemente genial, ojala y hagas un curso de Django o Laravel.

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