Guest User

Untitled

a guest
May 10th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. Install Django (2.0)
  2. ====================
  3.  
  4. ### Environment
  5.  
  6. * <b> Operating System</b> : Ubuntu 16.04 LTS (64-bit)
  7. * <b> Python</b> : 3.6.3
  8.  
  9. #### Create Virtual Environment
  10. ```
  11. python3 -m virtualenv --no-site-packages venv
  12. ```
  13.  
  14. #### Activate Virtual Environment
  15. ```
  16. source venv/bin/activate
  17. ```
  18.  
  19. #### Install Latest Django
  20. ```
  21. pip install django
  22. ```
  23.  
  24. #### Create A Django Project and Change to Project Directory
  25. ```
  26. django-admin startproject pythononlysite
  27. cd pythononlysite
  28. ```
  29.  
  30. #### Create An App
  31. ```
  32. python manage.py startapp pythononlyapp
  33. ```
  34.  
  35. #### Install MySQL Client
  36. ```
  37. pip install mysqlclient
  38. ```
  39.  
  40. #### Set up the database connection in `settings.py`
  41. ```
  42. DATABASES = {
  43. 'default': {
  44. 'ENGINE': 'django.db.backends.mysql',
  45. 'NAME': 'pythononly_db',
  46. 'USER': 'your_database_username',
  47. 'PASSWORD': 'your_password',
  48. 'HOST': 'localhost',
  49. 'PORT': '3306'
  50. }
  51. }
  52. ```
  53. #### Migrate the models
  54. ```
  55. python manage.py migrate
  56. ```
  57.  
  58. #### Run Project
  59. ```
  60. python manage.py runserver
  61. ```
  62.  
  63. #### Make Migrations of Models and Reflect them in Database
  64. ```
  65. python manage.py makemigrations pythononly
  66. python manage.py migrate
  67. ```
  68.  
  69. #### Open Python Shell Around Django API
  70. ```
  71. python manage.py shell
  72. ```
  73.  
  74. #### Create Super User
  75. ```
  76. python manage.py createsuperuser
  77. username:
  78. Email address:
  79. Password:
  80. ```
  81.  
  82. #### Settings for CKEDITOR in `settings.py`
  83. ```
  84. # starts added for static files
  85. from os.path import abspath, dirname, join, normpath, exists
  86. # Absolute filesystem path to the Django project directory:
  87. DJANGO_ROOT = dirname(abspath(__file__))
  88.  
  89. # Absolute filesystem path to the top-level project folder:
  90. SITE_ROOT = dirname(DJANGO_ROOT)
  91. STATIC_ROOT = join(SITE_ROOT, "site_media", "static")
  92. CKEDITOR_JQUERY_URL = '//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js'
  93.  
  94. CKEDITOR_CONFIGS = {
  95. 'default':
  96. {
  97. 'autoParagraph': False,
  98. 'toolbar': 'basic',
  99. 'allowedContent': True,
  100. },
  101. }
  102.  
  103. # end added for static files
  104.  
  105. # Application definition
  106.  
  107. INSTALLED_APPS = [
  108. 'newsletter.apps.NewsletterConfig', # this is the app
  109. 'django.contrib.admin',
  110. 'django.contrib.auth',
  111. 'django.contrib.contenttypes',
  112. 'django.contrib.sessions',
  113. 'django.contrib.messages',
  114. 'django.contrib.staticfiles',
  115. 'rest_framework',
  116. 'ckeditor'
  117. ]
  118. ```
  119.  
  120. #### Create Static Files
  121. ```
  122. python manage.py collectstatic
  123. ```
  124.  
  125. #### Adding CKEditor in `models.py`
  126. ```
  127. from django.db import models
  128.  
  129. from ckeditor.fields import RichTextField
  130.  
  131. class Newsletter(models.Model):
  132. lead_text = RichTextField()
  133. ```
Add Comment
Please, Sign In to add comment