Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Install Django (2.0)
- ====================
- ### Environment
- * <b> Operating System</b> : Ubuntu 16.04 LTS (64-bit)
- * <b> Python</b> : 3.6.3
- #### Create Virtual Environment
- ```
- python3 -m virtualenv --no-site-packages venv
- ```
- #### Activate Virtual Environment
- ```
- source venv/bin/activate
- ```
- #### Install Latest Django
- ```
- pip install django
- ```
- #### Create A Django Project and Change to Project Directory
- ```
- django-admin startproject pythononlysite
- cd pythononlysite
- ```
- #### Create An App
- ```
- python manage.py startapp pythononlyapp
- ```
- #### Install MySQL Client
- ```
- pip install mysqlclient
- ```
- #### Set up the database connection in `settings.py`
- ```
- DATABASES = {
- 'default': {
- 'ENGINE': 'django.db.backends.mysql',
- 'NAME': 'pythononly_db',
- 'USER': 'your_database_username',
- 'PASSWORD': 'your_password',
- 'HOST': 'localhost',
- 'PORT': '3306'
- }
- }
- ```
- #### Migrate the models
- ```
- python manage.py migrate
- ```
- #### Run Project
- ```
- python manage.py runserver
- ```
- #### Make Migrations of Models and Reflect them in Database
- ```
- python manage.py makemigrations pythononly
- python manage.py migrate
- ```
- #### Open Python Shell Around Django API
- ```
- python manage.py shell
- ```
- #### Create Super User
- ```
- python manage.py createsuperuser
- username:
- Email address:
- Password:
- ```
- #### Settings for CKEDITOR in `settings.py`
- ```
- # starts added for static files
- from os.path import abspath, dirname, join, normpath, exists
- # Absolute filesystem path to the Django project directory:
- DJANGO_ROOT = dirname(abspath(__file__))
- # Absolute filesystem path to the top-level project folder:
- SITE_ROOT = dirname(DJANGO_ROOT)
- STATIC_ROOT = join(SITE_ROOT, "site_media", "static")
- CKEDITOR_JQUERY_URL = '//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js'
- CKEDITOR_CONFIGS = {
- 'default':
- {
- 'autoParagraph': False,
- 'toolbar': 'basic',
- 'allowedContent': True,
- },
- }
- # end added for static files
- # Application definition
- INSTALLED_APPS = [
- 'newsletter.apps.NewsletterConfig', # this is the app
- 'django.contrib.admin',
- 'django.contrib.auth',
- 'django.contrib.contenttypes',
- 'django.contrib.sessions',
- 'django.contrib.messages',
- 'django.contrib.staticfiles',
- 'rest_framework',
- 'ckeditor'
- ]
- ```
- #### Create Static Files
- ```
- python manage.py collectstatic
- ```
- #### Adding CKEditor in `models.py`
- ```
- from django.db import models
- from ckeditor.fields import RichTextField
- class Newsletter(models.Model):
- lead_text = RichTextField()
- ```
Add Comment
Please, Sign In to add comment