1
1
#! /bin/bash
2
2
3
- # # create folder and cd into it
4
- # mkdir $1
5
- # folder=$1
6
- # while [[ $folder = "" ]]; do
7
- # read -p 'Name of folder cant be blank. Enter name of folder: ' folder
8
- # done
9
-
10
- # if [[ -z "$1" ]]; then
11
- # mkdir $folder
12
- # cd $folder
13
- # else
14
- # cd $folder
15
- # fi
16
-
17
- # pwd
18
-
19
- # # create vitual env and activate it
20
- # printf '\n'
21
- # python3 -m venv venv
22
- # source venv/bin/activate
23
-
24
- # # update pip
25
- # printf '\n'
26
- # python3 -m pip install --upgrade pip
27
-
28
- # # install django
29
- # printf '\nInstalling django\n'
30
- # pip install django
31
-
32
- # # django startproject base
33
- # printf '\n'
34
- # django-admin startproject base .
35
-
36
- # # django startapp $name_of_app
37
- # printf '\n\n'
38
- # read -p 'Enter name of app: ' app
39
- # while [[ $app = "" ]]; do
40
- # read -p 'App_name cannot be empty, Enter name of app: ' app
41
- # done
42
- # python3 manage.py startapp $app
43
-
44
- # # output
45
- # ls
3
+ # create folder and cd into it
4
+ mkdir $1
5
+ folder=$1
6
+ while [[ $folder = " " ]]; do
7
+ read -p ' Name of folder cant be blank. Enter name of folder: ' folder
8
+ done
46
9
10
+ printf ' \n# Creating project folder\n'
11
+
12
+ if [[ -z " $1 " ]]; then
13
+ mkdir $folder
14
+ cd $folder
15
+ else
16
+ cd $folder
17
+ fi
18
+
19
+ printf ' \n# Location of project: ' $( pwd) ' \n'
20
+
21
+ # create vitual env and activate it
22
+ printf ' \n# Creating and activating virtual enviroment (venv)\n'
23
+ python3 -m venv venv
24
+ source venv/bin/activate
25
+
26
+ # update pip
27
+ printf ' \n# Upgrading pip to latest version \n'
28
+ python3 -m pip install --upgrade pip
29
+
30
+ # install django
31
+ printf ' \n# Installing django and other requirements\n'
32
+ pip install django
33
+
34
+ # django startproject base
35
+ printf ' \n# Starting django project (base)\n'
36
+ django-admin startproject base .
37
+
38
+ # django startapp $name_of_app
39
+ printf ' \n\n'
40
+ read -p ' Enter name of app: ' app
41
+ while [[ $app = " " ]]; do
42
+ read -p ' App_name cannot be empty, Enter name of app: ' app
43
+ done
44
+ python3 manage.py startapp $app
45
+
46
+ # output
47
47
ls
48
- cd mytestapp
49
- ls
50
- touch urls
51
48
49
+ printf ' \n**************************** Writing to files **************************\n'
50
+
51
+ # base/settings.py
52
+ me=$( < /dev/urandom tr -dc ' A-Za-z0-9!#$%&' \' ' ()*+,-./:;<=>?@[\]^_`{|}~' | head -c 30)
53
+
54
+ cat > base/settings.py << _EOF_
55
+ import os
56
+
57
+ # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
58
+ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
59
+
60
+
61
+ # Quick-start development settings - unsuitable for production
62
+ # See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
63
+
64
+ # SECURITY WARNING: keep the secret key used in production secret!
65
+ SECRET_KEY = "$me "
66
+
67
+ # SECURITY WARNING: don't run with debug turned on in production!
68
+ DEBUG = True
69
+
70
+ ALLOWED_HOSTS = []
71
+
72
+
73
+ # Application definition
74
+
75
+ INSTALLED_APPS = [
76
+ 'django.contrib.admin',
77
+ 'django.contrib.auth',
78
+ 'django.contrib.contenttypes',
79
+ 'django.contrib.sessions',
80
+ 'django.contrib.messages',
81
+ 'django.contrib.staticfiles',
82
+ '$app ',
83
+ ]
84
+
85
+ MIDDLEWARE = [
86
+ 'django.middleware.security.SecurityMiddleware',
87
+ 'django.contrib.sessions.middleware.SessionMiddleware',
88
+ 'django.middleware.common.CommonMiddleware',
89
+ 'django.middleware.csrf.CsrfViewMiddleware',
90
+ 'django.contrib.auth.middleware.AuthenticationMiddleware',
91
+ 'django.contrib.messages.middleware.MessageMiddleware',
92
+ 'django.middleware.clickjacking.XFrameOptionsMiddleware',
93
+ ]
94
+
95
+ ROOT_URLCONF = 'base.urls'
96
+
97
+ TEMPLATES = [
98
+ {
99
+ 'BACKEND': 'django.template.backends.django.DjangoTemplates',
100
+ 'DIRS': [],
101
+ 'APP_DIRS': True,
102
+ 'OPTIONS': {
103
+ 'context_processors': [
104
+ 'django.template.context_processors.debug',
105
+ 'django.template.context_processors.request',
106
+ 'django.contrib.auth.context_processors.auth',
107
+ 'django.contrib.messages.context_processors.messages',
108
+ ],
109
+ },
110
+ },
111
+ ]
112
+
113
+ WSGI_APPLICATION = 'base.wsgi.application'
114
+
115
+
116
+ # Database
117
+ # https://docs.djangoproject.com/en/2.2/ref/settings/#databases
118
+
119
+ DATABASES = {
120
+ 'default': {
121
+ 'ENGINE': 'django.db.backends.sqlite3',
122
+ 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
123
+ }
124
+ }
125
+
126
+
127
+ # Password validation
128
+ # https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators
129
+
130
+ AUTH_PASSWORD_VALIDATORS = [
131
+ {
132
+ 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
133
+ },
134
+ {
135
+ 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
136
+ },
137
+ {
138
+ 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
139
+ },
140
+ {
141
+ 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
142
+ },
143
+ ]
144
+
145
+
146
+ # Internationalization
147
+ # https://docs.djangoproject.com/en/2.2/topics/i18n/
148
+
149
+ LANGUAGE_CODE = 'en-us'
150
+
151
+ TIME_ZONE = 'UTC'
152
+
153
+ USE_I18N = True
154
+
155
+ USE_L10N = True
156
+
157
+ USE_TZ = True
158
+
159
+
160
+ # Static files (CSS, JavaScript, Images)
161
+ # https://docs.djangoproject.com/en/2.2/howto/static-files/
162
+
163
+ STATIC_URL = '/static/'
164
+ _EOF_
165
+
166
+ printf ' \n created base/settings.py\n'
167
+
168
+ # app/urls.py
169
+ cat > $app /urls.py << _EOF_
170
+ from django.urls import path
171
+ from $app import views
172
+
173
+ urlpatterns = [
174
+ path('', views.home, name='home'),
175
+ ]
176
+ _EOF_
177
+
178
+ printf ' \n created ' $app ' /urls.py\n'
179
+
180
+ # base.urls.py
181
+ cat > base/urls.py << _EOF_
182
+ from django.contrib import admin
183
+ from django.urls import path, include
184
+
185
+ urlpatterns = [
186
+ path('admin/', admin.site.urls),
187
+ path('', include('$app .urls'))
188
+ ]
189
+ _EOF_
190
+
191
+ printf ' \n created base/urls.py\n'
192
+
193
+ # app/views.py
194
+ cat > $app /views.py << _EOF_
195
+ from django.shortcuts import render
196
+
197
+ def home(request):
198
+ return render(request, 'home.html', {})
199
+
200
+ _EOF_
201
+
202
+ printf ' \n created ' $app ' /views.py\n'
203
+
204
+
205
+ # templates/home.html
206
+ cd $app
207
+ mkdir templates
208
+ cat > templates/home.html << _EOF_
209
+ <!DOCTYPE html>
210
+ <html lang="en">
211
+ <head>
212
+ <meta charset="UTF-8">
213
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
214
+ <meta http-equiv="X-UA-Compatible" content="ie=edge">
215
+ <title>Home</title>
216
+ </head>
217
+ <body>
218
+ <h2>Home</h2>
219
+ </body>
220
+ </html>
221
+ _EOF_
222
+
223
+ printf ' \n created ' $app ' /templates/home.html\n'
224
+
225
+ cd ..
226
+
227
+ printf " \n ----------- starting server -------------\n\n"
228
+
229
+ python3 manage.py makemigrations
230
+ python3 manage.py migrate
231
+ python3 manage.py runserver
232
+
233
+
234
+ # jay='rrrr'
235
+ # printf '\n'$app' is mmmm'
0 commit comments