[django] 프로젝트 및 디비 생성, admin사이트, 사용자 사이트
- 공유 링크 만들기
- X
- 이메일
- 기타 앱
[django] 프로젝트 및 디비 생성, admin사이트, 사용자 사이트
간단 명료 django 프로젝트 생성 순서
http://1a2a3a4a.tistory.com/48
강좌 링크
http://blog.naver.com/nsjkim/140131180145
터미널 열어 프로젝트를 생성할 경로로 간다.
프로젝트 생성 명령어 :
django-admin.py startproject 프로젝트명
애플리케이션 생성 명령어 :
manage.py startapp 이름
suhyeon-ui-MacBook-Air:hompage rlatngus0333$ python manage.py startapp blog
suhyeon-ui-MacBook-Air:hompage rlatngus0333$ ls
blog hompage manage.py
프로젝트 테스트
웹프라우저 주소창에 http://localhost:8000 이라고 입력하면 아래와 같은 화면을 볼 수 있다.
http://wikidocs.net/read/842
참고하여 blog.models.py를 구성하자
옛날 글 강좌라 달라진 것이 있다. suhyeon-ui-MacBook-Air:hompage rlatngus0333$ ./manage.py sql blog 하면 나오는 에러 : blog app을 찾을 수 없어서 나오는 오류 이다. 더보기 접기 Traceback (most recent call last): File "manage.py", line 10, in execute_from_command_line(sys.argv) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line utility.execute() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 261, in fetch_command klass = load_command_class(app_name, subcommand) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 69, in load_command_class module = import_module('%s.management.commands.%s' % (app_name, name)) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module __import__(name) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/commands/sql.py", line 4, in from django.core.management.sql import sql_create File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/sql.py", line 6, in from django.db import models File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/__init__.py", line 40, in backend = load_backend(connection.settings_dict['ENGINE']) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/__init__.py", line 34, in __getattr__ return getattr(connections[DEFAULT_DB_ALIAS], item) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/utils.py", line 92, in __getitem__ backend = load_backend(db['ENGINE']) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/utils.py", line 51, in load_backend raise ImproperlyConfigured(error_msg) django.core.exceptions.ImproperlyConfigured: 'sqlite3' isn't an available database backend. Try using django.db.backends.sqlite3 instead. Error was: No module named base
접기
Title = models.CharField(max_length=40,null=False)
maxlength -> max_length로 해야 한다.
또한 setting.py에서
INSTALLED_APPS 에 App경로를 지정할 때
프로젝트/앱 이 아니고
앱
으로 바뀌엇다.
INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', 'blog', # Uncomment the next line to enable the admin: # 'django.contrib.admin', # Uncomment the next line to enable admin documentation: # 'django.contrib.admindocs', )
http://wikidocs.net/read/836 blog안에 admin.py 파일도 생성해야 한다.
from django.contrib import admin from blog.models import Entries
admin.site.register(Entries)
urls.py 확인 from django.conf.urls import patterns, include, url
# Uncomment the next two lines to enable the admin: from django.contrib import admin admin.autodiscover()
urlpatterns = patterns('', # Examples: # url(r'^$', 'hompage.views.home', name='home'), # url(r'^hompage/', include('hompage.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation: # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin: url(r'^admin/', include(admin.site.urls)), )
주석처리 해재
settings.py에서
INSTALLED_APPS 에서 django.contrib.sites 없애기 이유 보기 접기 You don't really need the sites framework if you only run one site from the project, so the easiest fix would be to remove the following item from your INSTALLED_APPS and the error should go away: 'django.contrib.sites' 접기 'django.contrib.admin', 추가하기
DATABASES = { DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. 'NAME': 'test', # Or path to database file if using sqlite3. 'USER': '', # Not used with sqlite3. 'PASSWORD': '', # Not used with sqlite3. 'HOST': '', # Set to empty string for localhost. Not used with sqlite3. 'PORT': '', # Set to empty string for default. Not used with sqlite3. } }
./manage.py syncdb ./manage.py runserver 8888 http://127.0.0.1:8888/admin/ 로 확인.
http://127.0.0.1:8888/enemy/ 로 접속.
sample.zip
파일 다운로드 후
./manage.py syncdb
만 해주면 기본적인 프로젝트 생성 완료. (model.py내용 수정)
from http://jenemia.tistory.com/163 by ccl(A) rewrite - 2020-03-07 12:55:17
- 공유 링크 만들기
- X
- 이메일
- 기타 앱
댓글
댓글 쓰기