From ccafc4f462414befc77db0eedbcadc45344f2bca Mon Sep 17 00:00:00 2001 From: xiaohuanshu Date: Tue, 20 Sep 2016 13:28:40 +0800 Subject: [PATCH] add avatar for user --- checkinsystem/settings_base.py | 2 ++ checkinsystem/urls.py | 9 ++++++++- media/README.MD | 1 + .../img/avatar5.png => media/avatar/default.png | Bin templates/header.html | 8 ++++---- user/models.py | 14 ++++++++++++++ .../commands/updateavatarforalluser.py | 16 ++++++++++++++++ 7 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 media/README.MD rename static/img/avatar5.png => media/avatar/default.png (100%) create mode 100644 wechat/management/commands/updateavatarforalluser.py diff --git a/checkinsystem/settings_base.py b/checkinsystem/settings_base.py index 1d1ae33..bf77639 100644 --- a/checkinsystem/settings_base.py +++ b/checkinsystem/settings_base.py @@ -96,6 +96,8 @@ STATICFILES_DIRS = ( os.path.join(BASE_DIR, "static"), ) +MEDIA_URL = '/media/' +MEDIA_ROOT = os.path.join(BASE_DIR, "media") SESSION_ENGINE = 'django.contrib.sessions.backends.cache' SESSION_EXPIRE_AT_BROWSER_CLOSE = True diff --git a/checkinsystem/urls.py b/checkinsystem/urls.py index 1d7702d..20f9855 100644 --- a/checkinsystem/urls.py +++ b/checkinsystem/urls.py @@ -13,7 +13,8 @@ 1. Import the include() function: from django.conf.urls import url, include 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) """ -from django.conf.urls import url,include +from django.conf.urls import url, include, patterns +from django.conf import settings urlpatterns = [ url(r'^$', 'center.views.home', name='home'), @@ -26,3 +27,9 @@ url(r'^rbac/', include('rbac.urls', namespace="rbac")), url(r'^seat$', 'center.views.seat', name='seat'), ] + +if settings.DEBUG: + urlpatterns += patterns('', + url(r'^media/(?P.*)$', 'django.views.static.serve', + {'document_root': settings.MEDIA_ROOT}), + ) diff --git a/media/README.MD b/media/README.MD new file mode 100644 index 0000000..c9a33ff --- /dev/null +++ b/media/README.MD @@ -0,0 +1 @@ +upload dir diff --git a/static/img/avatar5.png b/media/avatar/default.png similarity index 100% rename from static/img/avatar5.png rename to media/avatar/default.png diff --git a/templates/header.html b/templates/header.html index cc54a7b..774a9b5 100755 --- a/templates/header.html +++ b/templates/header.html @@ -59,18 +59,18 @@

- User Image + User Image