Curso Django. Creación primer proyecto. Vídeo 2
Introduction to Django and Project Setup
In this section, the instructor introduces the Django framework and discusses project setup. The benefits of installing Django in a virtual environment are explained, as well as the official database management systems supported by Django.
Installing Django Locally vs in a Virtual Environment
- Installing Django locally allows you to use the version of Django installed on your computer for all your projects.
- Working with a virtual environment provides the advantage of having multiple versions of Django on one machine, allowing for different project requirements.
- It is important to match the development, testing, and production environments to avoid compatibility issues.
Advantages of Using a Virtual Environment
- With a virtual environment, you can have multiple versions of Django and Python installed on the same machine.
- Different dependencies can be set up for each project.
- Allows for consistent development, testing, and production environments.
Importance of Matching Development Environments
- Development: The phase where the project is being built and not yet published.
- Testing: The project is published but still undergoing testing.
- Production: The final stage where the project is visible to everyone.
- Matching these environments ensures consistency and avoids compatibility problems.
Officially Supported Database Management Systems
- PostgreSQL (Postgres), MySQL, Oracle are officially supported by Django.
- SQLite3 comes pre-installed with recent versions of Python and requires no additional configuration.
Working with Different Database Management Systems
This section covers working with different database management systems in Django. The instructor explains that SQLite3 is used by default in recent versions of Python but also demonstrates how to work with other databases like PostgreSQL and MySQL.
Default Database Management System - SQLite3
- SQLite3 comes pre-installed with recent versions of Python.
- No additional configuration is required to use SQLite3 with Django.
Working with PostgreSQL
- PostgreSQL is a popular and powerful open-source database management system.
- It is recommended by Django for production environments.
- Configuration settings need to be updated in the Django settings file to connect to a PostgreSQL database.
Working with MySQL
- MySQL is another widely used open-source database management system.
- It can be used with Django by updating the configuration settings in the Django settings file.
Conclusion
The instructor concludes the video by summarizing the importance of using virtual environments, matching development environments, and working with different database management systems in Django.
Key Takeaways
- Installing Django in a virtual environment allows for flexibility and compatibility across different projects.
- Matching development, testing, and production environments ensures consistency and avoids compatibility issues.
- Officially supported database management systems like PostgreSQL, MySQL, and Oracle are recommended for use with Django.
Introduction to Creating Django Projects
In this section, the instructor explains how to create a Django project and set up the necessary folders and files.
Creating a Project Folder
- Create a folder on your computer where you will store your Django projects.
- Unlike other technologies like PHP, you can choose any location for this folder.
- The instructor demonstrates creating a folder named "proyectos_django" on the desktop.
Navigating to the Project Folder
- Open the system console and navigate to the directory where you created your project folder.
- Copy the path of the project folder to the clipboard.
Creating Your First Django Project
- Use the command
django-admin startproject <project_name>in the console, replacing<project_name>with your desired name for the project.
- The instructor names their first project "proyecto1".
- After executing the command, no output is expected in the console.
- Opening the project folder reveals two items: a file named "manage.py" and a subfolder with the same name as your project.
Understanding Important Files
- The "manage.py" file is crucial as it allows interaction with Django projects through various commands.
- Running
python manage.py helpprovides a list of available instructions and commands.
- Familiarize yourself with these commands throughout the course.
- Inside your project's subfolder, there are four important files:
- "init.py": An empty file that signifies this directory as a Python package.
- "settings.py": Contains all configurations for your Django project. It will be explored further when setting up an editor later in the course.
- "urls.py": Stores URL patterns used by your project. Similar to a table of contents in Word documents, it maps URLs to specific views or functions within your application.
- "wsgi.py": Relates to the web server used in your Django project.
Understanding the "settings.py" File
- Open the "settings.py" file with a text editor (e.g., Notepad) to explore its contents.
- The file contains Python code, including a list of installed applications.
- These applications include the admin interface, authentication system, and frameworks for handling sessions, messages, and static files.
- Some applications may require database tables to function properly.
- By default, Django uses SQLite3 as the database backend.
Activating Your Project and Database
- To activate your project and enable the installed applications to use the database, navigate back to your project folder in the console.
- Use the command
python manage.py migrateto create necessary database tables and apply any pending migrations.
Activating the Project and Running the Server
In this section, the instructor explains how to activate the project and run the server.
Activating the Project
- To activate the project, execute the command
python manage.py runserverin the terminal.
- Once activated, all code lines should appear as "ok" in the console.
- The project's database files will be located in the project folder.
Running the Server
- To run the server, execute
python manage.py runservercommand.
- Django comes with a lightweight development server for testing purposes.
- This server is not recommended for serious projects due to its limitations.
- The development server only supports single requests and cannot handle heavy workloads.
Accessing Django Welcome Page
In this section, we learn how to access Django's welcome page after running the server.
- After starting the server, open a web browser and enter
http://127.0.0.1:8000.
- If everything is working correctly, it should display Django's welcome page.
Successful Installation Confirmation
In this section, we confirm that our installation was successful.
- Upon accessing
http://127.0.0.1:8000, a successful installation message should be displayed.
Recommended Text Editors for Django Development
In this section, we explore recommended text editors for Django development.
- Popular free text editors include Atom and Visual Studio Code (VSCode).
- VSCode is highly recommended as it offers excellent features such as GitHub integration and support for multiple programming languages.