1월, 2016의 게시물 표시

django 에서 404, 500 에러 처리하기

django 에서 404, 500에러가 발생시 Debug=True로 하면 웹서버의 정보가 보이는데 실서버에 이관시에는 DEBUG=False로 해야 한다. 그런데 에러가 발생시 서버에서 발생하는 에러 페이지를 보여주기 때문에 우리가 만든 웹페이지를 보여주기 위해서는 아래와 같이 handler를 등록해주면 내가 보여주고 싶은 페이지를 볼 수 있다. 아래와 같이 설정을 한다. setting.py DEBUG = False urls 파일에서 view를 만들고 보여줄 페이지 뷰를 설정한다. urls.py handler404 = 'kid.views.page_not_found_view' handler500 = 'kid.views.page_not_found_view' views 파일에서 html를 render한다. views.py def page_not_found_view(request):     return render(request,'page_not_found.html',RequestContext(request))

django 에서 static file이 나오지 않을때

django 에서 static file이 나오지 않을때 아래와 같이 설정하면 된다. wsgi.py 를 반드시 설정하자. https://devcenter.heroku.com/articles/django-assets Django settings for static assets can be a bit difficult to configure and debug. However, if you just add the following settings to your  settings.py , everything should work exactly as expected: settings.py # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/1.7/howto/static-files/ BASE_DIR = os.path.dirname(os.path.abspath(__file__)) STATIC_ROOT = ' staticfiles ' STATIC_URL = ' /static/ ' STATICFILES_DIRS = ( os.path.join(BASE_DIR, ' static ' ), ) Django won’t automatically create the target directory that  collectstatic  uses, so we recommend adding a dummy file to your repository,  as seen here . Whitenoise By default, Django does not support serving static files in production. We recommend using the WhiteNoise  project for best-practice serving of static assets in production. Inst