๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

์ „์ฒด ๊ธ€77

[Django ์—๋Ÿฌ] The view mediapractice.views.create didn't return an HttpResponse object. It returned None instead. ์˜ค๋ฅ˜ ๋‚ด์šฉ: The view mediapractice.views.create didn't return an HttpResponse object. It returned None instead. view.create๊ฐ€ HttpResponse ๊ฐ์ฒด๋ฅผ ๋ฐ˜ํ™˜ํ•˜์ง€ ์•Š์Œ. ์•„๋ฌด๊ฒƒ๋„ ๋ฆฌํ„ดํ•˜์ง€ ์•Š์•˜๋‹ค. ์–ด์ฉŒ๋‹ค: forms๋ฅผ ์ด์šฉํ•ด์„œ ์ด๋ฏธ์ง€ ์˜ฌ๋ฆฌ๋Š” ๊ธฐ๋Šฅ์„ ๋งŒ๋“ค๋ ค๋‹ค ์ƒ๊ธด ์˜ค๋ฅ˜... ์˜คํƒ€ ์—†๋Š”์ง€, ํ•จ์ˆ˜, ๋ชจ๋ธ, ๋ชจ๋ธํผ, html ๋‹ค ๊ผผ๊ผผํžˆ ๋ดค๋Š”๋ฐ ๋ชป ์ฐพ๊ณ , ๊นƒํ—ˆ๋ธŒ์—์„œ ์ „์— ๋‚ด๊ฐ€ ์ผ๋˜ ์ฝ”๋“œ๋ฅผ ๋ดค๋‹ค. ์›์ธ: ํผ ํƒœ๊ทธ ์•ˆ์— enctype="multipart/form-data"๋ฅผ ์จ์ฃผ์ง€ ์•Š์•„์„œ ์ƒ๊ธด ์˜ค๋ฅ˜์˜€๋‹ค... ๋ฅผ ๋ผ๊ณ  ๊ณ ์ณ์ฃผ๋‹ˆ ์ž˜ ๋Œ์•„๊ฐ”๋‹ค. 2020. 7. 18.
[Django ์—๋Ÿฌ] CSRF verification failed. Request aborted. CSRF ๊ฒ€์ฆ ์‹คํŒจ. ์š”์ฒญ์ด ์ค‘๋‹จ๋จ. create.html์˜ ํผ ํƒœ๊ทธ ์•ˆ์— {%csrf_token%}์„ ๋„ฃ์–ด์ฃผ์ง€ ์•Š์•„์„œ ์ƒ๊ธด ๋ฌธ์ œ์ธ๋“ฏ ํ•˜๋‹ค. *์ฐธ๊ณ  -CSRF ๊ณต๊ฒฉ์ด๋ž€? Cross Site Request Forgery. ์›น ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์ทจ์•ฝ์  ์ค‘ ํ•˜๋‚˜์ด๋‹ค. ์ธํ„ฐ๋„ท ์‚ฌ์šฉ์ž(ํฌ์ƒ์ž)๊ฐ€ ์ž์‹ ์˜ ์˜๋„์™€๋Š” ๋ฌด๊ด€ํ•˜๊ฒŒ ๊ณต๊ฒฉ์ž๊ฐ€ ์˜๋„ํ•œ ํ–‰์œ„(์ˆ˜์ •, ์‚ญ์ œ, ๋“ฑ๋ก ๋“ฑ)๋ฅผ ์›น ์‚ฌ์ดํŠธ์— ์š”์ฒญํ•˜๊ฒŒํ•˜๋Š” ๊ณต๊ฒฉ์ด๋‹ค. -{%csrf_token%} CSRF ๊ณต๊ฒฉ์„ ๋ง‰๋Š” ์ฝ”๋“œ์ด๋‹ค. ํด๋ผ์ด์–ธํŠธ์—์„œ ํ•ด๋‹น ํŽ˜์ด์ง€๋ฅผ ์ ‘์†ํ•˜๋ฉด, Django์—์„œ csrf token์„ ๋ณด๋‚ด์–ด cookie์— ์ €์žฅํ•˜๊ณ , POST๋กœ ์ „์†กํ•  ๋•Œ csrf token์ด ํ•จ๊ป˜ ์ „์†ก๋˜์–ด ์ธ์ฆํ•˜๋Š” ๋ฐฉ์‹์ด๋‹ค. token์ด ์ •๋ณด๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์Œ. {%csrf_token%}์€ ๊ทธ๋ƒฅ ๋ณด์•ˆ.. 2020. 7. 18.
[Django note] #3 ๋‚ด๊ฐ€ ๋ณด๋ ค๊ณ  ๋งŒ๋“œ๋Š” ์žฅ๊ณ  ๋…ธํŠธ - update ํ•จ์ˆ˜, ์ˆ˜์ • ๊ธฐ๋Šฅ (์ „ ๋‚ด์šฉ์ด ๋ณด์ด๊ฒŒ ํ•˜๊ธฐ) ๋ฉ‹์‚ฌ ์žฅ๊ณ  ๊ฐ•์˜๋ฅผ ๋“ฃ๊ณ  update ํ•จ์ˆ˜๋ฅผ ์ •์˜ํ•˜๋ฉด์„œ, '์™œ ์ˆ˜์ •์ด๋ผ๋ฉด์„œ ๊ทธ๋ƒฅ ์ƒˆ ๊ธ€์“ฐ๋Š”๊ฑฐ๋ž‘ ๋˜‘๊ฐ™์€ ๋นˆ ์ฐฝ์ด ๋‚˜์˜ฌ๊นŒ..'๋ผ๋Š” ์ƒ๊ฐ์„ ํ–ˆ๋Š”๋ฐ, ์ •๋ง ๊ฐ์‚ฌํ•˜๊ฒŒ๋„ ์šด์˜์ง„๋‹˜์ด ๋‚ด ์ƒ๊ฐ์„ ์•Œ์•„์ฑ„์‹œ๊ณ  ๋จผ์ € ์•Œ๋ ค์ฃผ์…จ๋‹ค.....๐Ÿ˜ญ๐Ÿ˜ญ๐Ÿ‘๐Ÿ‘ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค... ๋‚ด ์ฝ”๋“œ(์ˆ˜์ • ํŽ˜์ด์ง€๋ฅผ ๋ณด๋ฉด ์ž…๋ ฅ๊ณต๊ฐ„์— ์•„๋ฌด ๊ฒƒ๋„ ์—†์ด ๋‚˜์˜ด) def update2(request, pk): portfolio = get_object_or_404(Portfolio, pk=pk) modify = NewPort(request.POST, request.FILES, instance=portfolio) if modify.is_valid(): modify.save() return redirect('portfolio') return render(r.. 2020. 7. 17.
[ONF] ํ“จ์ฆˆ 1๊ธฐ ๋ชจ์ง‘ ์šฐ์™€ ๋“œ๋””์–ด.. ์ ˆ๋Œ€ ํ•œ๋‹ค ์ •๋ง๋ฃจ 2020. 7. 17.
[Django ์—๋Ÿฌ] NOT NULL constraint failed: blogapp_blog.pub_date ์›์ธ: views.py์—์„œ newblog(์ƒˆ๋กœ์šด ๊ธ€์„์“ฐ๋Š” ํ•จ์ˆ˜)๋ฅผ ์ž˜ ๋ชป ์ •์˜ํ•จ. ์—๋Ÿฌ ๋‚œ ์ฝ”๋“œ #views.py ์—๋Ÿฌ ๋‚œ ์ฝ”๋“œ def newblog(request): if request.method=='POST': blog=BlogPost(request.POST) if blog.is_valid(): blog.save(commit=False) #ํ‹€๋ฆฐ ๋ถ€๋ถ„ blog.pub_date=timezone.now() blog.save() return redirect('home') else: blog=BlogPost() return render(request, 'new.html', {'blog':blog} ์ˆ˜์ •ํ•œ ์ฝ”๋“œ #views.py ์ˆ˜์ •ํ•œ ์ฝ”๋“œ def newblog(request): if request.metho.. 2020. 7. 17.
[Django note] #2 ๋‚ด๊ฐ€ ๋ณด๋ ค๊ณ  ๋งŒ๋“œ๋Š” ์žฅ๊ณ  ๋…ธํŠธ (ํ…œํ”Œ๋ฆฟ ์ƒ์†, url ๊ณ„์ธต์  ๊ด€๋ฆฌ) ํ…œํ”Œ๋ฆฟ ์ƒ์† 1. ํ”„๋กœ์ ํŠธ ํด๋” ์•ˆ์— templatesํด๋”๋ฅผ ๋งŒ๋“ค๊ณ  ๊ทธ ์•ˆ์— base.html ๋งŒ๋“ค๊ธฐ ์ค‘๋ณต๋˜๋Š” ๋‚ด์šฉ๋„ ์ฑ„์›Œ๋„ฃ๊ธฐ 2. settings.py์— base.html์˜ ์œ„์น˜๋ฅผ ์•Œ๋ ค์ฃผ๊ธฐ TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': ['ํ”„๋กœ์ ํŠธ ์ด๋ฆ„/templates'], 'APP_DIRS': True, ... 3. base.html์— ๋‚ด์šฉ์ด ๋“ค์–ด๊ฐˆ ๋ถ€๋ถ„์„ ์•Œ๋ ค์ฃผ๊ธฐ {%block contents%} {%endblock%} #block contents์—์„œ 'contents'๋Š” ๋ฐ”๊ฟ”์“ธ ์ˆ˜ ์žˆ๋‹ค. (title, sidebar ๋“ฑ๋“ฑ..) 4. ๋‚ด์šฉ์— ํ•ด๋‹นํ•˜๋Š” html๋กœ ๊ฐ€์„œ {%extends 'bas.. 2020. 7. 16.