├── .idea
├── DjangoGetStarted.iml
├── misc.xml
├── modules.xml
├── vcs.xml
└── workspace.xml
├── DjangoGetStarted
├── __init__.py
├── __init__.pyc
├── settings.py
├── settings.pyc
├── urls.py
├── urls.pyc
├── wsgi.py
└── wsgi.pyc
├── Readme.md
├── apps
├── __init__.py
└── message
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── admin.py
│ ├── admin.pyc
│ ├── apps.py
│ ├── migrations
│ ├── 0001_initial.py
│ ├── 0001_initial.pyc
│ ├── 0002_auto_20180107_1505.py
│ ├── 0002_auto_20180107_1505.pyc
│ ├── __init__.py
│ └── __init__.pyc
│ ├── models.py
│ ├── models.pyc
│ ├── tests.py
│ ├── views.py
│ └── views.pyc
├── db.sqlite3
├── form.html
├── manage.py
├── requirements.txt
├── static
└── css
│ └── style.css
└── templates
└── message_form.html
/.idea/DjangoGetStarted.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
28 |
29 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 | it Worked
68 | django.po
69 | STATIC_ROOT
70 | Meta
71 | ordering
72 | ave
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 | true
97 | DEFINITION_ORDER
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 | 1515253356172
252 |
253 |
254 | 1515253356172
255 |
256 |
257 | 1515258797339
258 |
259 |
260 |
261 | 1515258797339
262 |
263 |
264 | 1515268273378
265 |
266 |
267 |
268 | 1515268273378
269 |
270 |
271 | 1515275540305
272 |
273 |
274 |
275 | 1515275540306
276 |
277 |
278 | 1515310220424
279 |
280 |
281 |
282 | 1515310220424
283 |
284 |
285 | 1515319501129
286 |
287 |
288 |
289 | 1515319501129
290 |
291 |
292 | 1515331156300
293 |
294 |
295 |
296 | 1515331156300
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 |
367 |
368 |
369 |
370 |
371 |
372 |
373 |
374 |
375 |
376 |
377 |
378 |
379 |
380 |
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 |
389 |
390 |
391 |
392 |
393 |
394 |
395 |
396 |
397 |
398 |
399 |
400 |
401 |
402 |
403 |
404 |
405 |
406 |
407 |
408 |
409 |
410 |
411 |
412 |
413 |
414 |
415 |
416 |
417 |
418 |
419 |
420 |
421 |
422 |
423 |
424 |
425 |
426 |
427 |
428 |
429 |
430 |
431 |
432 |
433 |
434 |
435 |
436 |
437 |
438 |
439 |
440 |
441 |
442 |
443 |
444 |
445 |
446 |
447 |
448 |
449 |
450 |
451 |
452 |
453 |
454 |
455 |
456 |
457 |
458 |
459 |
460 |
461 |
462 |
463 |
464 |
465 |
466 |
467 |
468 |
469 |
470 |
471 |
472 |
473 |
474 |
475 |
476 |
477 |
478 |
479 |
480 |
481 |
482 |
483 |
484 |
485 |
486 |
487 |
488 |
489 |
490 |
491 |
492 |
493 |
494 |
495 |
496 |
497 |
498 |
499 |
500 |
501 |
502 |
503 |
504 |
505 |
506 |
507 |
508 |
509 |
510 |
511 |
512 |
513 |
514 |
515 |
516 |
517 |
518 |
519 |
520 |
521 |
522 |
523 |
524 |
525 |
526 |
527 |
528 |
529 |
530 |
531 |
532 |
533 |
534 |
535 |
536 |
537 |
538 |
539 |
540 |
541 |
542 |
543 |
544 |
545 |
546 |
547 |
548 |
549 |
550 |
551 |
552 |
553 |
554 |
555 |
556 |
557 |
558 |
559 |
560 |
561 |
562 |
563 |
564 |
565 |
566 |
567 |
568 |
569 |
570 |
571 |
572 |
573 |
574 |
575 |
576 |
577 |
578 |
579 |
580 |
581 |
582 |
583 |
584 |
585 |
586 |
587 |
588 |
589 |
590 |
591 |
592 |
593 |
594 |
595 |
596 |
597 |
598 |
599 |
600 |
601 |
602 |
603 |
604 |
605 |
606 |
607 |
608 |
609 |
610 |
611 |
612 |
613 |
614 |
615 |
616 |
617 |
618 |
619 |
620 |
621 |
622 |
623 |
624 |
625 |
626 |
627 |
628 |
629 |
630 |
631 |
632 |
633 |
634 |
635 |
636 |
637 |
638 |
639 |
640 |
641 |
642 |
643 |
644 |
645 |
646 |
647 |
648 |
649 |
650 |
651 |
652 |
653 |
654 |
655 |
656 |
657 |
658 |
659 |
660 |
661 |
662 |
663 |
664 |
665 |
666 |
667 |
668 |
669 |
670 |
671 |
672 |
673 |
674 |
675 |
676 |
677 |
678 |
679 |
680 |
681 |
682 |
683 |
684 |
685 |
686 |
687 |
688 |
689 |
690 |
691 |
692 |
693 |
694 |
695 |
696 |
697 |
698 |
699 |
700 |
701 |
702 |
703 |
704 |
705 |
706 |
707 |
708 |
709 |
710 |
711 |
712 |
713 |
714 |
715 |
716 |
717 |
718 |
719 |
720 |
721 |
722 |
723 |
724 |
725 |
726 |
727 |
728 |
--------------------------------------------------------------------------------
/DjangoGetStarted/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mtianyan/DjangoGetStarted/f6d36530866f8fab2bc5e1e8e456bf1ad2aec2a3/DjangoGetStarted/__init__.py
--------------------------------------------------------------------------------
/DjangoGetStarted/__init__.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mtianyan/DjangoGetStarted/f6d36530866f8fab2bc5e1e8e456bf1ad2aec2a3/DjangoGetStarted/__init__.pyc
--------------------------------------------------------------------------------
/DjangoGetStarted/settings.py:
--------------------------------------------------------------------------------
1 | """
2 | Django settings for DjangoGetStarted project.
3 |
4 | Generated by 'django-admin startproject' using Django 1.9.8.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/1.9/topics/settings/
8 |
9 | For the full list of settings and their values, see
10 | https://docs.djangoproject.com/en/1.9/ref/settings/
11 | """
12 | import sys
13 | import os
14 |
15 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
16 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
17 | # print BASE_DIR
18 | # print os.path.join(BASE_DIR,'apps')
19 | sys.path.insert(0,os.path.join(BASE_DIR,'apps'))
20 | # sys.path.insert(0,os.path.join(BASE_DIR,'extra_apps'))
21 |
22 | # Quick-start development settings - unsuitable for production
23 | # See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/
24 |
25 | # SECURITY WARNING: keep the secret key used in production secret!
26 | SECRET_KEY = 'f*0mdf6nt(j%y5p4dy-(v+z6ka5zfc2servh&!@gyk5vp*rru+'
27 |
28 | # SECURITY WARNING: don't run with debug turned on in production!
29 | DEBUG = True
30 |
31 | ALLOWED_HOSTS = []
32 |
33 |
34 | # Application definition
35 |
36 | INSTALLED_APPS = [
37 | 'django.contrib.admin',
38 | 'django.contrib.auth',
39 | 'django.contrib.contenttypes',
40 | 'django.contrib.sessions',
41 | 'django.contrib.messages',
42 | 'django.contrib.staticfiles',
43 | 'message'
44 | ]
45 |
46 | MIDDLEWARE_CLASSES = [
47 | 'django.middleware.security.SecurityMiddleware',
48 | 'django.contrib.sessions.middleware.SessionMiddleware',
49 | 'django.middleware.common.CommonMiddleware',
50 | 'django.middleware.csrf.CsrfViewMiddleware',
51 | 'django.contrib.auth.middleware.AuthenticationMiddleware',
52 | 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
53 | 'django.contrib.messages.middleware.MessageMiddleware',
54 | 'django.middleware.clickjacking.XFrameOptionsMiddleware',
55 | ]
56 |
57 | ROOT_URLCONF = 'DjangoGetStarted.urls'
58 |
59 | TEMPLATES = [
60 | {
61 | 'BACKEND': 'django.template.backends.django.DjangoTemplates',
62 | 'DIRS': [os.path.join(BASE_DIR, 'templates')]
63 | ,
64 | 'APP_DIRS': True,
65 | 'OPTIONS': {
66 | 'context_processors': [
67 | 'django.template.context_processors.debug',
68 | 'django.template.context_processors.request',
69 | 'django.contrib.auth.context_processors.auth',
70 | 'django.contrib.messages.context_processors.messages',
71 | ],
72 | },
73 | },
74 | ]
75 |
76 | WSGI_APPLICATION = 'DjangoGetStarted.wsgi.application'
77 |
78 |
79 | # Database
80 | # https://docs.djangoproject.com/en/1.9/ref/settings/#databases
81 |
82 | DATABASES = {
83 | 'default': {
84 | 'ENGINE': 'django.db.backends.mysql',
85 | 'NAME': 'testdjango',
86 | 'USER': 'root',
87 | 'PASSWORD': 'tp158917',
88 | 'HOST': "127.0.0.1"
89 | }
90 | }
91 |
92 |
93 | # Password validation
94 | # https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators
95 |
96 | AUTH_PASSWORD_VALIDATORS = [
97 | {
98 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
99 | },
100 | {
101 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
102 | },
103 | {
104 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
105 | },
106 | {
107 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
108 | },
109 | ]
110 |
111 |
112 | # Internationalization
113 | # https://docs.djangoproject.com/en/1.9/topics/i18n/
114 |
115 | LANGUAGE_CODE = 'en-us'
116 |
117 | TIME_ZONE = 'UTC'
118 |
119 | USE_I18N = True
120 |
121 | USE_L10N = True
122 |
123 | USE_TZ = True
124 |
125 |
126 | # Static files (CSS, JavaScript, Images)
127 | # https://docs.djangoproject.com/en/1.9/howto/static-files/
128 |
129 | STATIC_URL = '/static/'
130 | STATICFILES_DIRS = [
131 | os.path.join(BASE_DIR, 'static')
132 | ]
--------------------------------------------------------------------------------
/DjangoGetStarted/settings.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mtianyan/DjangoGetStarted/f6d36530866f8fab2bc5e1e8e456bf1ad2aec2a3/DjangoGetStarted/settings.pyc
--------------------------------------------------------------------------------
/DjangoGetStarted/urls.py:
--------------------------------------------------------------------------------
1 | """DjangoGetStarted URL Configuration
2 |
3 | The `urlpatterns` list routes URLs to views. For more information please see:
4 | https://docs.djangoproject.com/en/1.9/topics/http/urls/
5 | Examples:
6 | Function views
7 | 1. Add an import: from my_app import views
8 | 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
9 | Class-based views
10 | 1. Add an import: from other_app.views import Home
11 | 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
12 | Including another URLconf
13 | 1. Import the include() function: from django.conf.urls import url, include
14 | 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
15 | """
16 | from django.conf.urls import url
17 | from django.contrib import admin
18 | from message.views import getform
19 | from message import views
20 |
21 | urlpatterns = [
22 | url(r'^admin/', admin.site.urls),
23 | url(r'^form/$', getform, name="form_new"),
24 |
25 | # url(r'^form', getform, name="form_new"),
26 | # url(r'^formtest',admin.site.urls)
27 | ]
28 |
--------------------------------------------------------------------------------
/DjangoGetStarted/urls.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mtianyan/DjangoGetStarted/f6d36530866f8fab2bc5e1e8e456bf1ad2aec2a3/DjangoGetStarted/urls.pyc
--------------------------------------------------------------------------------
/DjangoGetStarted/wsgi.py:
--------------------------------------------------------------------------------
1 | """
2 | WSGI config for DjangoGetStarted project.
3 |
4 | It exposes the WSGI callable as a module-level variable named ``application``.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/1.9/howto/deployment/wsgi/
8 | """
9 |
10 | import os
11 |
12 | from django.core.wsgi import get_wsgi_application
13 |
14 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "DjangoGetStarted.settings")
15 |
16 | application = get_wsgi_application()
17 |
--------------------------------------------------------------------------------
/DjangoGetStarted/wsgi.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mtianyan/DjangoGetStarted/f6d36530866f8fab2bc5e1e8e456bf1ad2aec2a3/DjangoGetStarted/wsgi.pyc
--------------------------------------------------------------------------------
/Readme.md:
--------------------------------------------------------------------------------
1 | # DjangoGetStarted
2 |
3 | [](https://travis-ci.org/mtianyan/hexoBlog-Github)
4 | [](https://gitter.im/mtianyan/DjangoGetStarted?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
5 | [](https://opensource.org/licenses/mit-license.php)
6 |
7 | A simple django project,I hope it can help you to learn the Django Basic Use Method
8 |
9 | ## Quick Start
10 |
11 | ```
12 | $ git clone https://github.com/mtianyan/DjangoGetStarted.git
13 | $ cd DjangoGetStarted
14 | $ pip install -r requirements.txt
15 | ```
16 |
17 | [Download the MySQL_python_1.2.5_cp27_none_win_amd64.whl](https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python)
18 |
19 | ```
20 | $ pip install MySQL_python_1.2.5_cp27_none_win_amd64.whl
21 | $ python manage.py runserver
22 | ```
23 |
24 | use the address: http://127.0.0.1:8000/form/
25 |
26 | ## Background:
27 |
28 | - 最近重装了系统,所以从环境配置开始,我都做到尽可能从零开始,对初学者友好。
29 | - 自己已经学习Python一年了,最近对于Python相关开始进行一个较全面复习。
30 | - 希望可以帮到那些对于Python,对Django有兴趣的同学少走弯路。
31 |
32 | [项目线上演示地址](http://mxonline.mtianyan.cn)
33 | [原版视频课程地址:](https://coding.imooc.com/learn/list/78.html)
34 |
35 | >一次性的一个完整项目代码很难被学习,所以我采用commit记录源码快照 + 阶段性教程结合的形式。类似关卡式学习概念。
36 |
37 | - 每节教程前面会写明对应的上节commit:开始某一节教程的前置条件。
38 | - 每节教程后面会写明对应的已结束commit: 方便本节出错参考。
39 |
40 | 希望可以对Django初学者,Python爱好者有所帮助。
41 |
42 | ## Contents:
43 |
44 | #### 1. [项目演示和课程介绍](http://blog.mtianyan.cn/post/e4b77eed.html)
45 | #### 2. [开发环境搭建](http://blog.mtianyan.cn/post/d2647be6.html)
46 | #### 3. django基础知识回顾
47 | #### 4. 数据库设计和xadmin搭建后台管理系统
48 | #### 5. 系统功能模块实现
49 | #### 6. web系统知识以及网络安全
50 | #### 7. xadmin扩展知识
51 |
52 | ## About me
53 | [简书](https://www.jianshu.com/u/db9a7a0daa1f) && [mtianyan's blog](http://blog.mtianyan.cn/)
54 |
55 | 有趣的Python群:619417153
56 |
57 | 欢迎关注简书,star项目!谢谢!
58 |
59 | 你的关注支持是我继续分享前进的动力。
60 |
--------------------------------------------------------------------------------
/apps/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mtianyan/DjangoGetStarted/f6d36530866f8fab2bc5e1e8e456bf1ad2aec2a3/apps/__init__.py
--------------------------------------------------------------------------------
/apps/message/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mtianyan/DjangoGetStarted/f6d36530866f8fab2bc5e1e8e456bf1ad2aec2a3/apps/message/__init__.py
--------------------------------------------------------------------------------
/apps/message/__init__.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mtianyan/DjangoGetStarted/f6d36530866f8fab2bc5e1e8e456bf1ad2aec2a3/apps/message/__init__.pyc
--------------------------------------------------------------------------------
/apps/message/admin.py:
--------------------------------------------------------------------------------
1 | from django.contrib import admin
2 |
3 | # Register your models here.
4 |
--------------------------------------------------------------------------------
/apps/message/admin.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mtianyan/DjangoGetStarted/f6d36530866f8fab2bc5e1e8e456bf1ad2aec2a3/apps/message/admin.pyc
--------------------------------------------------------------------------------
/apps/message/apps.py:
--------------------------------------------------------------------------------
1 | from __future__ import unicode_literals
2 |
3 | from django.apps import AppConfig
4 |
5 |
6 | class MessageConfig(AppConfig):
7 | name = 'apps.message'
8 |
--------------------------------------------------------------------------------
/apps/message/migrations/0001_initial.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # Generated by Django 1.9.8 on 2018-01-07 06:32
3 | from __future__ import unicode_literals
4 |
5 | from django.db import migrations, models
6 |
7 |
8 | class Migration(migrations.Migration):
9 |
10 | initial = True
11 |
12 | dependencies = [
13 | ]
14 |
15 | operations = [
16 | migrations.CreateModel(
17 | name='UserMessage',
18 | fields=[
19 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
20 | ('name', models.CharField(max_length=20, verbose_name='\u7528\u6237\u540d')),
21 | ('email', models.EmailField(max_length=254, verbose_name='\u90ae\u7bb1')),
22 | ('address', models.CharField(max_length=100, verbose_name='\u8054\u7cfb\u5730\u5740')),
23 | ('message', models.CharField(max_length=500, verbose_name='\u7559\u8a00\u4fe1\u606f')),
24 | ],
25 | options={
26 | 'verbose_name': '\u7528\u6237\u7559\u8a00\u4fe1\u606f',
27 | },
28 | ),
29 | ]
30 |
--------------------------------------------------------------------------------
/apps/message/migrations/0001_initial.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mtianyan/DjangoGetStarted/f6d36530866f8fab2bc5e1e8e456bf1ad2aec2a3/apps/message/migrations/0001_initial.pyc
--------------------------------------------------------------------------------
/apps/message/migrations/0002_auto_20180107_1505.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # Generated by Django 1.9.8 on 2018-01-07 07:05
3 | from __future__ import unicode_literals
4 |
5 | from django.db import migrations, models
6 |
7 |
8 | class Migration(migrations.Migration):
9 |
10 | dependencies = [
11 | ('message', '0001_initial'),
12 | ]
13 |
14 | operations = [
15 | migrations.RemoveField(
16 | model_name='usermessage',
17 | name='id',
18 | ),
19 | migrations.AddField(
20 | model_name='usermessage',
21 | name='object_id',
22 | field=models.CharField(default='', max_length=50, primary_key=True, serialize=False, verbose_name='\u4e3b\u952e'),
23 | ),
24 | migrations.AlterField(
25 | model_name='usermessage',
26 | name='name',
27 | field=models.CharField(blank=True, default='', max_length=20, null=True, verbose_name='\u7528\u6237\u540d'),
28 | ),
29 | ]
30 |
--------------------------------------------------------------------------------
/apps/message/migrations/0002_auto_20180107_1505.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mtianyan/DjangoGetStarted/f6d36530866f8fab2bc5e1e8e456bf1ad2aec2a3/apps/message/migrations/0002_auto_20180107_1505.pyc
--------------------------------------------------------------------------------
/apps/message/migrations/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mtianyan/DjangoGetStarted/f6d36530866f8fab2bc5e1e8e456bf1ad2aec2a3/apps/message/migrations/__init__.py
--------------------------------------------------------------------------------
/apps/message/migrations/__init__.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mtianyan/DjangoGetStarted/f6d36530866f8fab2bc5e1e8e456bf1ad2aec2a3/apps/message/migrations/__init__.pyc
--------------------------------------------------------------------------------
/apps/message/models.py:
--------------------------------------------------------------------------------
1 | # coding: utf-8
2 | from __future__ import unicode_literals
3 |
4 | from django.db import models
5 |
6 | # Create your models here.
7 |
8 |
9 | # 继承于django.db.models.Model
10 | class UserMessage(models.Model):
11 | object_id = models.CharField(primary_key=True, max_length=50,default="", verbose_name="主键")
12 | # 设置最大长度,verbose_name在后台显示字段会用到
13 | name = models.CharField(max_length=20,null=True,blank=True,default="", verbose_name=u"用户名")
14 | # Django提供内置的邮箱字段会帮忙验证` default_validators = [validators.validate_email]`
15 | email = models.EmailField(verbose_name=u"邮箱")
16 | address = models.CharField(max_length=100, verbose_name=u"联系地址")
17 | message = models.CharField(max_length=500, verbose_name=u"留言信息")
18 |
19 | class Meta:
20 | verbose_name = u"用户留言信息"
21 |
22 | # 指明复数信息,否则后台显示"用户留言s"
23 | verbose_name_plural = verbose_name
24 |
25 | # 这里我们让它自动生成所以不用指定db-table
26 | # db_table = user_message
27 |
28 | # ordering指定默认排序字段,如:
29 | # ordering = ['-object_id']
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/apps/message/models.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mtianyan/DjangoGetStarted/f6d36530866f8fab2bc5e1e8e456bf1ad2aec2a3/apps/message/models.pyc
--------------------------------------------------------------------------------
/apps/message/tests.py:
--------------------------------------------------------------------------------
1 | from django.test import TestCase
2 |
3 | # Create your tests here.
4 |
--------------------------------------------------------------------------------
/apps/message/views.py:
--------------------------------------------------------------------------------
1 | # coding:utf-8
2 | from django.shortcuts import render
3 | # import MySQLdb
4 | from .models import UserMessage
5 | # Create your views here.
6 |
7 |
8 | def getform(request):
9 | """
10 | :param request:
11 | :return: render后的HttpResponse
12 | """
13 | # 3-5 查询部分
14 | message = None
15 | all_message = UserMessage.objects.filter(name='mtianyan', address='西安')
16 |
17 | # if 判断是否存在数据
18 | if all_message:
19 | # all_message是一个list,可以使用切片。
20 | message = all_message[0]
21 | # message = all_message[2:8]
22 |
23 | # UserMessage默认的数据管理器objects
24 | # 方法1 :all()是将所有数据返回成一个queryset类型(django的内置类型)
25 | # all_message = UserMessage.objects.all()
26 |
27 | # 方法2 :filter取出指定条件值,逗号代表and 必须同时满足两个条件才返回。
28 | # all_message = UserMessage.objects.filter(name='mtianyan', address='西安')
29 |
30 | # 删除操作
31 |
32 | # all_message.delete()
33 |
34 |
35 | # 我们可以对于all_message进行遍历操作
36 | # for message in all_message:
37 | # message.delete()
38 | # # 每个message实际就是一个UserMessage对象(这时我们就可以使用对象的相关方法)。
39 | # print message.name
40 |
41 | # 存储部分
42 |
43 | # 首先实例化一个对象
44 | # user_message = UserMessage()
45 |
46 | # 为对象增加属性
47 |
48 | # user_message.name = "mtianyan2"
49 | # user_message.message = "blog.mtianyan.cn"
50 | # user_message.address = "西安"
51 | # user_message.email = "1147727180@qq.com"
52 | # user_message.object_id = "efgh"
53 |
54 | # 调用save方法进行保存
55 | # user_message.save()
56 |
57 | # html表单部分
58 |
59 | # 此处对应html中的method="post",表示我们只处理post请求
60 | # if request.method == "POST":
61 | # # 就是取字典里key对应value值而已。取name,取不到默认空
62 | # name = request.POST.get('name', '')
63 | # message = request.POST.get('message', '')
64 | # address = request.POST.get('address', '')
65 | # email = request.POST.get('email', '')
66 | #
67 | # # 实例化对象
68 | # user_message = UserMessage()
69 | #
70 | # # 将html的值传入我们实例化的对象.
71 | # user_message.name = name
72 | # user_message.message = message
73 | # user_message.address = address
74 | # user_message.email = email
75 | # user_message.object_id = "ijkl"
76 | #
77 | # # 调用save方法进行保存
78 | # user_message.save()
79 |
80 | return render(request, 'message_form.html',{
81 | "my_message" : message
82 | })
83 |
84 |
85 | # # 使用原生sql获取书的列表
86 | # def book_list(request):
87 | # # 创建到数据库的连接: 指明用户名,数据库,密码
88 | # db = MySQLdb.connect(user = 'me', db='mydb', passwd='secret', host='localhost')
89 | # # 创建一个游标对象执行器
90 | # cursor = db.cursor()
91 | # # 书写我们需要的sql语句
92 | # cursor.execute('SELECT name FROM books ORDER BY name')
93 | # # 对于fetchall()的结果做遍历,将遍历回来的结果当做数组,取第0个值name。
94 | # names = [row[0] for row in cursor.fetchall()]
95 | # db.close()
96 |
97 |
--------------------------------------------------------------------------------
/apps/message/views.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mtianyan/DjangoGetStarted/f6d36530866f8fab2bc5e1e8e456bf1ad2aec2a3/apps/message/views.pyc
--------------------------------------------------------------------------------
/db.sqlite3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mtianyan/DjangoGetStarted/f6d36530866f8fab2bc5e1e8e456bf1ad2aec2a3/db.sqlite3
--------------------------------------------------------------------------------
/form.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
99 |
100 |
101 |
135 |
136 |
137 |
--------------------------------------------------------------------------------
/manage.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | import os
3 | import sys
4 |
5 | if __name__ == "__main__":
6 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "DjangoGetStarted.settings")
7 |
8 | from django.core.management import execute_from_command_line
9 |
10 | execute_from_command_line(sys.argv)
11 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | Django==1.9.8
2 |
--------------------------------------------------------------------------------
/static/css/style.css:
--------------------------------------------------------------------------------
1 |
2 | .smart-green {
3 | margin-left: auto;
4 | margin-right: auto;
5 | max-width: 500px;
6 | background: #F8F8F8;
7 | padding: 30px 30px 20px 30px;
8 | font: 12px Arial, Helvetica, sans-serif;
9 | color: #666;
10 | border-radius: 5px;
11 | -webkit-border-radius: 5px;
12 | -moz-border-radius: 5px;
13 | }
14 |
15 | .smart-green h1 {
16 | font: 24px "Trebuchet MS", Arial, Helvetica, sans-serif;
17 | padding: 20px 0px 20px 40px;
18 | display: block;
19 | margin: -30px -30px 10px -30px;
20 | color: #FFF;
21 | background: #9DC45F;
22 | text-shadow: 1px 1px 1px #949494;
23 | border-radius: 5px 5px 0px 0px;
24 | -webkit-border-radius: 5px 5px 0px 0px;
25 | -moz-border-radius: 5px 5px 0px 0px;
26 | border-bottom: 1px solid #89AF4C;
27 | }
28 |
29 | .smart-green h1 > span {
30 | display: block;
31 | font-size: 11px;
32 | color: #FFF;
33 | }
34 |
35 | .smart-green label {
36 | display: block;
37 | margin: 0px 0px 5px;
38 | }
39 |
40 | .smart-green label > span {
41 | float: left;
42 | margin-top: 10px;
43 | color: #5E5E5E;
44 | }
45 |
46 | .smart-green input[type="text"], .smart-green input[type="email"], .smart-green textarea, .smart-green select {
47 | color: #555;
48 | height: 30px;
49 | line-height: 15px;
50 | width: 100%;
51 | padding: 0px 0px 0px 10px;
52 | margin-top: 2px;
53 | border: 1px solid #E5E5E5;
54 | background: #FBFBFB;
55 | outline: 0;
56 | -webkit-box-shadow: inset 1px 1px 2px rgba(238, 238, 238, 0.2);
57 | box-shadow: inset 1px 1px 2px rgba(238, 238, 238, 0.2);
58 | font: normal 14px/14px Arial, Helvetica, sans-serif;
59 | }
60 |
61 | .smart-green textarea {
62 | height: 100px;
63 | padding-top: 10px;
64 | }
65 |
66 |
67 | .smart-green .button {
68 | background-color: #9DC45F;
69 | border-radius: 5px;
70 | -webkit-border-radius: 5px;
71 | -moz-border-border-radius: 5px;
72 | border: none;
73 | padding: 10px 25px 10px 25px;
74 | color: #FFF;
75 | text-shadow: 1px 1px 1px #949494;
76 | }
77 |
78 | .smart-green .button:hover {
79 | background-color: #80A24A;
80 | }
81 |
82 | .error-msg{
83 | color: red;
84 | margin-top: 10px;
85 | }
86 | .success-msg{
87 | color: #80A24A;
88 | margin-top: 10px;
89 | margin-bottom: 10px;
90 | }
91 |
--------------------------------------------------------------------------------
/templates/message_form.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
47 |
48 |
49 |
--------------------------------------------------------------------------------