Code Monkey home page Code Monkey logo

poll_site's Introduction

Getting started:

Creating a virtual environment

python -m venv envname

installing django

python -m pip install django

starting a django project

django-admin startproject myproject

starting the development server

python manage.py runserver

running the project on a specific port

python manage.py runserver 8080

creating a django app

The app should be created in the same folder as the manage.py so that it is imported as its own top level module rather than a submodule of the project python manage.py startapp appname

settings.py

setting up databases

[database documentation link](https://docs.djangoproject.com/en/4.1/ref/settings/#std-setting-DATABASES)

Add an app to the installed apps

Add an object path to the installed Apps array in the settings.py like polls.apps.PollsConfig

Make migrations for new changes in an app

python manage.py makemigrations appname

apply those migrations to the database

python manage.py migrate

Return SQL of a migration

python manage.py sqlmigrate appname 0001

Check for problems in the project witthout running migrations

python manage.py check

Use django in shell

python manage.py shell

API

Django Admin

Creating an Admin user

python manage.py createsuperuser

Timezone

change timezone to your current timezone using [timezone reference](https://docs.djangoproject.com/en/4.1/ref/settings/#std-setting-TIME_ZONE)

Tests

Running tests

python manage.py test appname

Testing a view

Use django test client to simulate a user interacting with the code at the view level. It can be used in the test.py or even in the view

Setting up the view test environment

[from django.test.utils import setup_test_environment setup_test_environment()] setup_test_environment() installs a template renderer which allows us to examine some additional attributes on responses such as context that would otherwise be unavailable. This method doesn't set up a test database.

Import the test client class

from django.test import Client

Create an instance of the client

client=Client()

Testing the view in shell

Testing the view in shell

To access Django source files:

python -c "import django; print(django.__path__)"

poll_site's People

Contributors

alwoch avatar

Watchers

 avatar

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.