Best VPN Service (English Banners)

GeekBuying.com

Using Django to Build a Website (Mac) 1-6

Alibaba Cloud
Autonomous Standing Desk

System Mechanic® Ultimate Defense™
Save up to 50% on ANSI Standards Packages

img_20191115_2026597989234256401445307.jpg

SS-MacBook:~ liveuk$ cd env1

IK Multimedia's T-RackS 5

SS-MacBook:env1 liveuk$ ls

django_test project1_env

SS-MacBook:env1 liveuk$ cd project_env

Autonomous Standing Desk

-bash: cd: project_env: No such file or directory

SS-MacBook:env1 liveuk$ cd project1_env

SS-MacBook:project1_env liveuk$ source bin/activate

(project1_env) SS-MacBook:project1_env liveuk$ ls

bin lib

include pip-selfcheck.json

(project1_env) SS-MacBook:project1_env liveuk$ mkdir src

(project1_env) SS-MacBook:project1_env liveuk$ cd src

(project1_env) SS-MacBook:src liveuk$ ls

(project1_env) SS-MacBook:src liveuk$ cd ..

(project1_env) SS-MacBook:project1_env liveuk$ cd src

(project1_env) SS-MacBook:src liveuk$ ls

(project1_env) SS-MacBook:src liveuk$ django-admin startproject trydjango

(project1_env) SS-MacBook:src liveuk$ ls

trydjango

(project1_env) SS-MacBook:src liveuk$ django-admin startproject trydjango .

(project1_env) SS-MacBook:src liveuk$ ls

manage.py trydjango

(project1_env) SS-MacBook:src liveuk$ cd ..

(project1_env) SS-MacBook:project1_env liveuk$ ls

bin lib src

include pip-selfcheck.json

(project1_env) SS-MacBook:project1_env liveuk$ rm -rf src

(project1_env) SS-MacBook:project1_env liveuk$ ls

bin lib

include pip-selfcheck.json

(project1_env) SS-MacBook:project1_env liveuk$ mkdir src

(project1_env) SS-MacBook:project1_env liveuk$ ls

bin lib src

include pip-selfcheck.json

(project1_env) SS-MacBook:project1_env liveuk$ cd scr

-bash: cd: scr: No such file or directory

(project1_env) SS-MacBook:project1_env liveuk$ cd src

(project1_env) SS-MacBook:src liveuk$ ls

(project1_env) SS-MacBook:src liveuk$ django-admin startproject trydjango .

(project1_env) SS-MacBook:src liveuk$ ls

manage.py trydjango

(project1_env) SS-MacBook:src liveuk$ python manage.py runserver

Performing system checks…

System check identified no issues (0 silenced).

You have 14 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.

Run ‘python manage.py migrate’ to apply them.

November 15, 2019 – 20:01:06

Django version 2.0.7, using settings ‘trydjango.settings’

Starting development server at http://127.0.0.1:8000/

Quit the server with CONTROL-C.

^C(project1_env) SS-MacBook:src liveuk$ ls

db.sqlite3 manage.py trydjango

(project1_env) SS-MacBook:src liveuk$ python manage.py migrate

Operations to perform:

Apply all migrations: admin, auth, contenttypes, sessions

Running migrations:

Applying contenttypes.0001_initial… OK

Applying auth.0001_initial… OK

Applying admin.0001_initial… OK

Applying admin.0002_logentry_remove_auto_add… OK

Applying contenttypes.0002_remove_content_type_name… OK

Applying auth.0002_alter_permission_name_max_length… OK

Applying auth.0003_alter_user_email_max_length… OK

Applying auth.0004_alter_user_username_opts… OK

Applying auth.0005_alter_user_last_login_null… OK

Applying auth.0006_require_contenttypes_0002… OK

Applying auth.0007_alter_validators_add_error_messages… OK

Applying auth.0008_alter_user_username_max_length… OK

Applying auth.0009_alter_user_last_name_max_length… OK

Applying sessions.0001_initial… OK

(project1_env) SS-MacBook:src liveuk$ python manage.py migrate

Operations to perform:

Apply all migrations: admin, auth, contenttypes, sessions

Running migrations:

No migrations to apply.

(project1_env) SS-MacBook:src liveuk$ python manage.py createsuperuser

Username (leave blank to use ‘liveuk’): mytestsuperuser

Email address: sy517@hotmail.co.uk

Password:

Password (again):

Superuser created successfully.

(project1_env) SS-MacBook:src liveuk$ ls

db.sqlite3 manage.py trydjango

(project1_env) SS-MacBook:src liveuk$ pwd

/Users/liveuk/env1/project1_env/src

(project1_env) SS-MacBook:src liveuk$ python manage.py startapp products

IN products/models.py

from django.db import models

# Create your models here.
class Product(models.Model):
title = models.CharField(max_length=120)
description = models.TextField(blank=True, null=True)
price = models.DecimalField(decimal_places=2, max_digits=1000)
summary = models.TextField(default=’Must Buy’)

IN settings.py

# Application definition

INSTALLED_APPS = [
‘django.contrib.admin’,
‘django.contrib.auth’,
‘django.contrib.contenttypes’,
‘django.contrib.sessions’,
‘django.contrib.messages’,
‘django.contrib.staticfiles’,
‘products’
]

(project1_env) SS-MacBook:src liveuk$ python manage.py makemigrations

Migrations for ‘products’:

products/migrations/0001_initial.py

– Create model Product

(project1_env) SS-MacBook:src liveuk$ python manage.py migrate

Operations to perform:

Apply all migrations: admin, auth, contenttypes, products, sessions

Running migrations:

Applying products.0001_initial… OK

(project1_env) SS-MacBook:src liveuk$ python manage.py migrate

Operations to perform:

Apply all migrations: admin, auth, contenttypes, products, sessions

Running migrations:

No migrations to apply.

(project1_env) SS-MacBook:src liveuk$ ls

db.sqlite3 manage.py products trydjango

 

IN products/admin.py (41:00/3:45:40)

from django.contrib import admin

# Register your models here.
#relative import
from .models import Product

admin.site.register(Product)

 

 

 

(project1_env) SS-MacBook:src liveuk$ python manage.py shell

Python 3.6.5 |Anaconda, Inc.| (default, Apr 26 2018, 08:42:37)

[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin

Type “help”, “copyright”, “credits” or “license” for more information.

(InteractiveConsole)

>>> from products.models import Product

>>> #import class Product

>>> Product.object.all()

Traceback (most recent call last):

File “<console>”, line 1, in <module>

AttributeError: type object ‘Product’ has no attribute ‘object’

>>> Product.objects.all()

<QuerySet [<Product: Product object (1)>, <Product: Product object (2)>]>

>>> Product.objects.create(title=’new pro3′, description = ‘another one’, price=)

File “<console>”, line 1

Product.objects.create(title=’new pro3′, description = ‘another one’, price=)

^

SyntaxError: invalid syntax

>>> Product.objects.create(title=’new pro3′, description = ‘another one’, price=’123′)

<Product: Product object (3)>

>>> Product.objects.create(title=’new pro3′, description = ‘another one’, price=’123′)

<Product: Product object (4)>