GithubHelp home page GithubHelp logo

django-test's Introduction

Getting started

python manage.py runserver

Visit http://127.0.0.1:8000/

If there is an error that claims polls is missing, you'll need to install my django-polls app.

# I had to use pip3 instead of pip to get this to work
pip3 install --user path/to/django-polls/dist/django-polls-0.1.tar.gz

Migrations

After changing a model, database migrations will need to be generated and applied.

python manage.py makemigrations polls
python manage.py migrate

To preview what sort of database query is generated by any given migration, run (replacing 0001 with the migration number of your choice)...

python manage.py sqlmigrate polls 0001

Shell sandbox

Import modules, apps and models to fiddle with them.

python manage.py shell

For example, test adding, updating and deleting items from the database via models.

python manage.py shell
>>> from polls.models import Question
>>> from django.utils import timezone
>>> q = Question(question_text="What's up?", pub_date=timezone.now())
>>> q.save()
>>> q.choice_set.create(choice_text='The sky', votes=0)
>>> c = q.choice_set.create(choice_text='Just hacking again', votes=0)
>>> c.delete()
>>> q.choice_set.count()

Admin

After rulling runserver (as above in "Getting started"), visit at http://127.0.0.1:8000/admin/

Create a user with:

python manage.py createsuperuser

Takeaways

I got to familiarized myself with...

  • Django's project structure
  • General workflow
  • Customizing the Admin interface
  • The relationship between models, views and templates
  • How to make and apply database migrations
  • How to handle basic HTTP requests
  • Django's routing system via urlpatterns
  • How to apply relative links without hardcoding URL paths
  • How to render simple HTML pages
  • How to create custom Django packages, and install them

django-test's People

Contributors

jeffkamo 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.