파이썬

파이썬을 활용한 자동화, 데이터 처리, 간단한 개발 사례를 공유합니다.

파이썬

Django 로그를 파일에 기록하기

Django를 이용하여 프로젝트를 만들고 애플리케이션을 추가한 경우, 기본 설정에서는 로그가 파일에 기록되지 않는다. 로그를 파일에 기록하기 위해서는 setting.py에 있는 ‘LOGGING’ 영역에 로그 파일 설정을 추가해야 한다. # A sample logging configuration. The only tangible logging # performed by this configuration is to send an email to # the site admins on every HTTP 500 error when DEBUG=False. # See http://docs.djangoproject.com/en/dev/topics/logging for # more details on how to customize your logging configuration. LOG_FILE = os.path.join(os.path.dirname(__file__), ‘..’, ‘site.log’) LOGGING = {     ‘version’: 1,     ‘disable_existing_loggers’: False,     ‘filters’: {         ‘require_debug_false’: {             ‘()’: ‘django.utils.log.RequireDebugFalse’         }     },     ‘handlers’: {         ‘mail_admins’: {             ‘level’: ‘ERROR’,             ‘filters’: [‘require_debug_false’],             ‘class’: ‘django.utils.log.AdminEmailHandler’         },         ‘logfile’: {             ‘class’: ‘logging.handlers.WatchedFileHandler’,             ‘filename’: LOG_FILE         },     },     ‘loggers’: {         ‘django.request’: {             ‘handlers’: [‘mail_admins’],             ‘level’: ‘ERROR’, […]

파이썬

error: Unable to find vcvarsall.bat

error: Unable to find vcvarsall.bat Python, Django, MariaDB를 이용하여 간단한 웹 애플리케이션을 만들어 보려고 한다. 그런데 Mysql 연동을 위한 패키지를 설치하면 ‘vcvarsall.bat’ 파일이 없다는 에러가 발생한다. [root@C:helloworld]#pip install MySQL-python Collecting MySQL-python C:Python27libsite-packagespip-8.1.2-py2.7.eggpip_vendorrequestspackagesurllib3utilssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS cert ificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#snimissingwarning.   SNIMissingWarning C:Python27libsite-packagespip-8.1.2-py2.7.eggpip_vendorrequestspackagesurllib3utilssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.   InsecurePlatformWarning   Downloading MySQL-python-1.2.5.zip (108kB)     100% |################################| 112kB 1.1MB/s Installing collected packages: MySQL-python   Running setup.py install for MySQL-python … error     Complete output from command C:Python27python.exe -u -c “import setuptools, tokenize;__file__=’c:\users\ray\appdata\local\temp\pip-build-fvz0fq\MySQL-python\setup.py’;exec(compile(getattr(tokenize, ‘open’, open)(__file__).read().replace(‘rn’, ‘n’), __file__, ‘exec’))” install –record c: usersrayappdatalocaltemppip-bz89ng-recordinstall-record.txt –single-version-externally-managed –compile:     running install     running build     running build_py     creating build     creating buildlib.win32-2.7     copying _mysql_exceptions.py -> buildlib.win32-2.7     creating buildlib.win32-2.7MySQLdb     copying MySQLdb__init__.py -> buildlib.win32-2.7MySQLdb     copying MySQLdbconverters.py -> buildlib.win32-2.7MySQLdb     copying MySQLdbconnections.py -> buildlib.win32-2.7MySQLdb     copying MySQLdbcursors.py -> buildlib.win32-2.7MySQLdb     copying MySQLdbrelease.py -> buildlib.win32-2.7MySQLdb     copying MySQLdbtimes.py -> buildlib.win32-2.7MySQLdb     creating buildlib.win32-2.7MySQLdbconstants     copying MySQLdbconstants__init__.py -> buildlib.win32-2.7MySQLdbconstants

파이썬

Python + Django : No module named MySQLdb

Django에서 MariaDB 연동 중 아래처럼 MySQLdb 모듈이 없다는 에러가 난다면, 모듈을 설치해야 한다. C:project1>manage.py syncdb Traceback (most recent call last):   File “C:project1manage.py”, line 10, in <module>     execute_from_command_line(sys.argv)   File “C:Python27libsite-packagesdjangocoremanagement__init__.py”, line 443, in execute_from_command_line     utility.execute()   File “C:Python27libsite-packagesdjangocoremanagement__init__.py”, line 382, in execute     self.fetch_command(subcommand).run_from_argv(self.argv)   File “C:Python27libsite-packagesdjangocoremanagement__init__.py”, line 261, in fetch_command     klass = load_command_class(app_name, subcommand)   File “C:Python27libsite-packagesdjangocoremanagement__init__.py”, line 69, in load_command_class     module = import_module(‘%s.management.commands.%s’ % (app_name, name))   File “C:Python27libsite-packagesdjangoutilsimportlib.py”, line 35, in import_module     __import__(name)   File “C:Python27libsite-packagesdjangocoremanagementcommandssyncdb.py”, line 8, in <module>     from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal   File “C:Python27libsite-packagesdjangocoremanagementsql.py”, line 6, in <module>     from django.db import models   File “C:Python27libsite-packagesdjangodb__init__.py”, line 40, in <module>     backend = load_backend(connection.settings_dict[‘ENGINE’])   File “C:Python27libsite-packagesdjangodb__init__.py”, line 34, in __getattr__     return getattr(connections[DEFAULT_DB_ALIAS], item)   File “C:Python27libsite-packagesdjangodbutils.py”, line 92, in __getitem__     backend = load_backend(db[‘ENGINE’])   File “C:Python27libsite-packagesdjangodbutils.py”, line 24, in load_backend     return import_module(‘.base’, backend_name)   File “C:Python27libsite-packagesdjangoutilsimportlib.py”, line 35, in import_module     __import__(name)   File “C:Python27libsite-packagesdjangodbbackendsmysqlbase.py”, line 16, in <module>     raise ImproperlyConfigured(“Error loading MySQLdb module: %s” % e) django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb C:project1> Colored by Color Scripter cs OS가 윈도우인 경우에는 아래 명령어를

파이썬

Python, Django 설치 및 환경설정

Photo by Christin Hume on Unsplash Python을 설치하고, 환경변수를 설정한다. 그리고 Django를 설치하면 끝이다. Python 설치 python-2.7.5.msi를 설치한다. 환경변수 설정 PATH에 아래 경로를 추가한다. C:Python27;C:Python27Scripts; setuptools 설치 setuptools-1.1.zip 파일의 압축을 해제한다. 그리고 CMD 창에서 압축을 해제한 경로로 이동하여 아래 명령을 차례대로 실행한다. ez_setup.py easy_install pip Django 설치 CMD 창에서 아래 명령어를 실행한다. 버전 번호를 기술하지

위로 스크롤