Giter Club home page Giter Club logo

djangoapp's Introduction

Project Setup with Poetry

  1. create a new poetry project;
  2. Create virtual env and activate it;
  3. use poetry add django, asgiref and sqlparse command to add django latest version to the pyproject.toml file; this command does also installs django in the virtual env;

Side Notes

  • pyproject.toml lists all the project dependencies;

  • poetry.lock keeps all the project dependencies constant so that if other people want to use your project, they will be able to install the exact same versions;

  • see also Setting up a basic Django project with Poetry

Initiate a Django project

  • Return to the terminal. In the terminal, create a Django project called my_project in the current directory.

  • poetry run runs the django-admin command for me from the virtual environment that will have all the dependencies that we specified earlier

  • Remember that the shortcut to refer to the current directory is a single dot . at the end of the command.

Initiate a Django project with the Django admin command:

poetry run django-admin startproject my_project .

Command syntax:

django-admin startproject project_name directory_name

  • Return to the terminal and start the Django server with the following command:

poetry run python3 manage.py runserver

  • Open your browser and see a bare-bones Django project.

Creating a Django app

  • Now we have a Django project created, we need to make an app. To do this, we use the manage.py file. In the terminal, type:

poetry run python3 manage.py startapp hello_world

  • Note: Check the explorer panel to see the new hello_world app directory has been created.

Creating Views

  • In hello_world/views.py, below from django.shortcuts import render, type:

from django.http import HttpResponse

  • add a Python function named index. Inside the function, we are returning a simple HTTP response.

Adding our app to the settings.py file

  • To connect the app you will need to scroll down through the my_project/settings.py file to find the INSTALLED_APPS list.

Test your app

poetry run python3 manage.py runserver

djangoapp's People

Contributors

kkumyk avatar

Watchers

 avatar

djangoapp's Issues

View paginated list of posts

As a site user, I can view a paginated list of posts so that I can select which post I want to view.

  • Given more than one post in the database, these multiple posts are listed.
  • When a user opens the main page a list of posts is seen.
  • Then the user sees all post titles with pagination to choose what to read.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.