質問編集履歴

2

追加

2020/11/24 01:40

投稿

yamatar
yamatar

スコア4

test CHANGED
File without changes
test CHANGED
@@ -58,7 +58,7 @@
58
58
 
59
59
  """
60
60
 
61
- Django settings for geodj project.
61
+ Django settings for deploy project.
62
62
 
63
63
 
64
64
 
@@ -88,7 +88,7 @@
88
88
 
89
89
  ###admin画面の表示設定
90
90
 
91
- admin.AdminSite.site_title = 'ログイン'
91
+ admin.AdminSite.site_title = 'ログインページ'
92
92
 
93
93
  admin.AdminSite.site_header = '管 理 画 面'
94
94
 
@@ -104,41 +104,7 @@
104
104
 
105
105
 
106
106
 
107
- #####windows用 gdal設定
108
-
109
- if os.name == 'nt':
107
+ ## osgeo4wはlocal_settings.pyに移動 ##
110
-
111
- import platform
112
-
113
-
114
-
115
- POSTGRES = r"C:\Program Files\PostgreSQL\9.6"
116
-
117
- OSGEO4W = r"C:\OSGeo4W"
118
-
119
- if '64' in platform.architecture()[0]:
120
-
121
- OSGEO4W += "64"
122
-
123
- assert os.path.isdir(OSGEO4W), "Directory does not exist: " + OSGEO4W
124
-
125
-
126
-
127
- os.environ['OSGEO4W_ROOT'] = OSGEO4W
128
-
129
- os.environ['POSTGRES_ROOT'] = POSTGRES
130
-
131
- os.environ['GDAL_LIBRARY_PATH'] = OSGEO4W + r"\bin"
132
-
133
- os.environ['GEOS_LIBRARY_PATH'] = OSGEO4W + r"\bin"
134
-
135
- os.environ['GDAL_DATA'] = OSGEO4W + r"\share\gdal"
136
-
137
- os.environ['PROJ_LIB'] = OSGEO4W + r"\share\proj"
138
-
139
- os.environ['PATH'] = OSGEO4W + r"\bin;" + POSTGRES + r"\bin;" + os.environ['PATH']
140
-
141
- #####
142
108
 
143
109
 
144
110
 
@@ -158,7 +124,7 @@
158
124
 
159
125
  # SECURITY WARNING: keep the secret key used in production secret!
160
126
 
161
- SECRET_KEY = '118#9w_tjpu^(3kq1#2f356&%t-h6&^o$ugxlqt^br^2ei_3j('
127
+ SECRET_KEY = '8@x_612*9gnu=f)es2)_y8%h(h_=fjgajn1t644dj#v*oh8hd2'
162
128
 
163
129
 
164
130
 
@@ -170,7 +136,7 @@
170
136
 
171
137
  ALLOWED_HOSTS = [
172
138
 
173
- "アプリ名.herokuapp.com"
139
+ "アプリ名"
174
140
 
175
141
  ]
176
142
 
@@ -178,11 +144,59 @@
178
144
 
179
145
 
180
146
 
147
+ # Application definition
148
+
149
+
150
+
151
+ INSTALLED_APPS = [
152
+
153
+ 'django.contrib.admin',
154
+
155
+ 'django.contrib.auth',
156
+
157
+ 'django.contrib.contenttypes',
158
+
159
+ 'django.contrib.sessions',
160
+
161
+ 'django.contrib.messages',
162
+
163
+ 'django.contrib.staticfiles',
164
+
165
+ 'django.templatetags.static',
166
+
167
+ 'django.contrib.gis',
168
+
169
+ 'django_cleanup.apps.CleanupConfig', # django-cleanup
170
+
171
+ 'map.apps.MapConfig',
172
+
173
+ 'deploy',
174
+
175
+ 'leaflet',
176
+
177
+ 'six',
178
+
179
+ 'django_filters',
180
+
181
+ 'rest_framework',
182
+
183
+ 'rest_framework_gis',
184
+
185
+ 'markdown',
186
+
187
+ 'PIL',
188
+
189
+ 'PIL.ExifTags',
190
+
191
+ ]
192
+
193
+
194
+
181
195
  MIDDLEWARE = [
182
196
 
183
197
  'django.middleware.security.SecurityMiddleware',
184
198
 
185
- 'whitenoise.middleware.WhiteNoiseMiddleware',#heroku追加
199
+ 'whitenoise.middleware.WhiteNoiseMiddleware', # heroku追加
186
200
 
187
201
  'django.contrib.sessions.middleware.SessionMiddleware',
188
202
 
@@ -200,7 +214,7 @@
200
214
 
201
215
 
202
216
 
203
- ROOT_URLCONF = 'geodj.urls'
217
+ ROOT_URLCONF = 'deploy.urls'
204
218
 
205
219
 
206
220
 
@@ -236,7 +250,7 @@
236
250
 
237
251
 
238
252
 
239
- WSGI_APPLICATION = 'geodj.wsgi.application'
253
+ WSGI_APPLICATION = 'deploy.wsgi.application'
240
254
 
241
255
 
242
256
 
@@ -246,7 +260,7 @@
246
260
 
247
261
  # https://docs.djangoproject.com/en/3.0/ref/settings/#databases
248
262
 
249
-
263
+ """
250
264
 
251
265
  DATABASES = {
252
266
 
@@ -254,7 +268,7 @@
254
268
 
255
269
  'ENGINE': 'django.contrib.gis.db.backends.postgis',
256
270
 
257
- 'NAME': 'geodjangodb2',
271
+ 'NAME': 'geodjangodb3',
258
272
 
259
273
  'USER': 'geo_admin',
260
274
 
@@ -264,325 +278,429 @@
264
278
 
265
279
  'PORT':'5432',#heroku
266
280
 
281
+ }
282
+
283
+ }
284
+
285
+ """
286
+
287
+
288
+
289
+ # Password validation
290
+
291
+ # https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
292
+
293
+
294
+
295
+ AUTH_PASSWORD_VALIDATORS = [
296
+
297
+ {
298
+
299
+ 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
300
+
267
301
  },
268
302
 
303
+ {
304
+
305
+ 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
306
+
269
- }
307
+ },
270
-
271
-
272
-
308
+
273
- INSTALLED_APPS = [
309
+ {
274
-
275
- 'django.contrib.admin',
310
+
276
-
277
- 'django.contrib.auth',
278
-
279
- 'django.contrib.contenttypes',
280
-
281
- 'django.contrib.sessions',
282
-
283
- 'django.contrib.messages',
284
-
285
- 'django.contrib.staticfiles',
286
-
287
- 'django.templatetags.static',
288
-
289
- 'django.contrib.gis',
290
-
291
- 'django_cleanup.apps.CleanupConfig', # django-cleanup
311
+ 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
292
-
293
- 'map.apps.MapConfig',
312
+
294
-
295
- 'geodj',
296
-
297
- 'leaflet',
298
-
299
- 'six',
313
+ },
300
-
314
+
301
- 'django_filters',
315
+ {
302
-
303
- 'rest_framework',
316
+
304
-
305
- 'rest_framework_gis',
317
+ 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
306
-
307
- 'markdown',
318
+
308
-
309
- 'PIL',
319
+ },
310
-
311
- 'PIL.ExifTags',
312
320
 
313
321
  ]
314
322
 
315
323
 
316
324
 
317
- # Password validation
318
-
319
- # https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
320
-
321
-
322
-
323
- AUTH_PASSWORD_VALIDATORS = [
324
-
325
- {
326
-
327
- 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
328
-
329
- },
330
-
331
- {
332
-
333
- 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
334
-
335
- },
336
-
337
- {
338
-
339
- 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
340
-
341
- },
342
-
343
- {
344
-
345
- 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
346
-
347
- },
325
+
326
+
327
+ # Internationalization
328
+
329
+ # https://docs.djangoproject.com/en/3.0/topics/i18n/
330
+
331
+
332
+
333
+ LANGUAGE_CODE = 'ja-JP'
334
+
335
+
336
+
337
+ TIME_ZONE = 'Asia/Tokyo'
338
+
339
+
340
+
341
+ USE_I18N = True
342
+
343
+
344
+
345
+ USE_L10N = True
346
+
347
+
348
+
349
+ USE_TZ = True
350
+
351
+
352
+
353
+
354
+
355
+ # ログイン後、10時間でタイムアウト
356
+
357
+ SESSION_COOKIE_AGE = 36000
358
+
359
+
360
+
361
+ # Static files (CSS, JavaScript, Images)
362
+
363
+ # https://docs.djangoproject.com/en/3.0/howto/static-files/
364
+
365
+
366
+
367
+ STATIC_URL = '/static/'
368
+
369
+ STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')#元はstatic
370
+
371
+ STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)#元はmap/atatic
372
+
373
+ # ↓ heroku追加
374
+
375
+ STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
376
+
377
+
378
+
379
+ MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
380
+
381
+ MEDIA_URL = '/media/'
382
+
383
+
384
+
385
+ # heroku用
386
+
387
+ try:
388
+
389
+ from .local_settings import *
390
+
391
+ except ImportError:
392
+
393
+ pass
394
+
395
+
396
+
397
+ if not DEBUG:
398
+
399
+ import django_heroku
400
+
401
+ django_heroku.settings(locals())
402
+
403
+ import dj_database_url
404
+
405
+ DATABASES['default'] = dj_database_url.config()
406
+
407
+ DATABASES['default']['ENGINE'] = 'django.contrib.gis.db.backends.postgis'
408
+
409
+ GDAL_LIBRARY_PATH = os.getenv('GDAL_LIBRARY_PATH')
410
+
411
+ GEOS_LIBRARY_PATH = os.getenv('GEOS_LIBRARY_PATH')
412
+
413
+ ```
414
+
415
+ ```procfile
416
+
417
+ web: gunicorn geodj.wsgi --log-file -
418
+
419
+ ```
420
+
421
+ requirements.txt
422
+
423
+ ```requirements
424
+
425
+ asgiref==3.2.9
426
+
427
+ brotlipy==0.7.0
428
+
429
+ certifi==2020.6.20
430
+
431
+ cffi==1.14.0
432
+
433
+ chardet==3.0.4
434
+
435
+ cryptography==2.9.2
436
+
437
+ dj-database-url==0.5.0
438
+
439
+ Django==3.0.7
440
+
441
+ django-cleanup==5.1.0
442
+
443
+ django-cors-headers==3.2.1
444
+
445
+ django-filter==2.3.0
446
+
447
+ django-heroku==0.3.1
448
+
449
+ django-leaflet==0.27.1
450
+
451
+ djangorestframework==3.11.0
452
+
453
+ djangorestframework-gis==0.15
454
+
455
+ fastcache==1.1.0
456
+
457
+ future==0.18.2
458
+
459
+ glob2==0.7
460
+
461
+ gunicorn==20.0.4
462
+
463
+ idna==2.9
464
+
465
+ importlib-metadata==1.6.1
466
+
467
+ Markdown==3.2.2
468
+
469
+ mpmath==1.1.0
470
+
471
+ olefile==0.46
472
+
473
+ Pillow==7.2.0
474
+
475
+ psycopg2==2.8.5
476
+
477
+ psycopg2-binary==2.8.6
478
+
479
+ pycparser==2.20
480
+
481
+ pyOpenSSL==19.1.0
482
+
483
+ PySocks==1.7.1
484
+
485
+ pytz==2020.1
486
+
487
+ requests==2.24.0
488
+
489
+ six==1.14.0
490
+
491
+ sqlparse==0.3.1
492
+
493
+ sympy==1.6.2
494
+
495
+ urllib3==1.25.9
496
+
497
+ whitenoise==5.2.0
498
+
499
+ win-inet-pton==1.1.0
500
+
501
+ wincertstore==0.2
502
+
503
+ zipp==3.1.0
504
+
505
+ ```
506
+
507
+ wsgi.py
508
+
509
+ ```wsgi
510
+
511
+ """
512
+
513
+ WSGI config for geodj project.
514
+
515
+
516
+
517
+ It exposes the WSGI callable as a module-level variable named ``application``.
518
+
519
+
520
+
521
+ For more information on this file, see
522
+
523
+ https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/
524
+
525
+ """
526
+
527
+
528
+
529
+ import os
530
+
531
+ from django.core.wsgi import get_wsgi_application
532
+
533
+
534
+
535
+ os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'geodj.settings')
536
+
537
+
538
+
539
+ application = get_wsgi_application()
540
+
541
+ ```
542
+
543
+ ### 試したこと
544
+
545
+ heroku run python manage.py checkしても
546
+
547
+ System check identified no issues (0 silenced).となり問題なさそうです。
548
+
549
+
550
+
551
+ djangoアプリを作り直したところ、アプリのurl/adminとすると
552
+
553
+ デフォルトのログイン画面(自分で作ったログイン画面ではない)が表示されます。
554
+
555
+ 管理画面で登録したデータがherokuのデータベースに登録できていることを
556
+
557
+ 確認できました。
558
+
559
+ 管理画面からサイト画面に移るとserver error(500)となり、
560
+
561
+ 上記と同じエラーログがでています。
562
+
563
+ 管理画面が見れて、indexなどが見れないということはpathがおかしいのでしょうか?
564
+
565
+ ```url
566
+
567
+ #url.py
568
+
569
+
570
+
571
+ from django.contrib import admin
572
+
573
+ from django.urls import include, path
574
+
575
+ from map.views import areaViewSet,upl_imgsViewSet
576
+
577
+ from rest_framework.routers import DefaultRouter
578
+
579
+ from map.views import index, GeojsonAPIView, upload
580
+
581
+ # 画像表示用
582
+
583
+ from . import settings
584
+
585
+ from django.contrib.staticfiles.urls import static
586
+
587
+ from django.contrib.staticfiles.urls import staticfiles_urlpatterns
588
+
589
+
590
+
591
+ router = DefaultRouter()
592
+
593
+ router.register('area', areaViewSet)# area用
594
+
595
+ router.register('upl_imgs', upl_imgsViewSet)# upl_imgs用
596
+
597
+
598
+
599
+ urlpatterns = [
600
+
601
+ path('admin/', admin.site.urls),
602
+
603
+ path('api/', include(router.urls)),
604
+
605
+ path('accounts/', include('django.contrib.auth.urls')),
606
+
607
+ path('', index, name='map_index'),
608
+
609
+ path('map/geojson/', GeojsonAPIView.as_view(), name='geojson_view'),
610
+
611
+ path('upload/', upload, name='upload'),
348
612
 
349
613
  ]
350
614
 
351
-
352
-
353
-
354
-
355
- # Internationalization
356
-
357
- # https://docs.djangoproject.com/en/3.0/topics/i18n/
358
-
359
-
360
-
361
- LANGUAGE_CODE = 'ja-JP'
362
-
363
-
364
-
365
- TIME_ZONE = 'Asia/Tokyo'
366
-
367
-
368
-
369
- USE_I18N = True
370
-
371
-
372
-
373
- USE_L10N = True
374
-
375
-
376
-
377
- USE_TZ = True
615
+ # 画像表示用
378
-
379
-
380
-
381
- # ログイン後、10時間でタイムアウト
616
+
382
-
383
- SESSION_COOKIE_AGE = 36000
384
-
385
-
386
-
387
- # Static files (CSS, JavaScript, Images)
617
+ urlpatterns += staticfiles_urlpatterns()
388
-
389
- # https://docs.djangoproject.com/en/3.0/howto/static-files/
618
+
390
-
391
-
392
-
393
- STATIC_URL = '/static/'
394
-
395
- STATIC_ROOT = os.path.join(BASE_DIR, 'static')
396
-
397
- STATICFILES_DIRS = (os.path.join(BASE_DIR, 'map/static'),)
619
+ urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
398
-
399
- # ↓ heroku追加
620
+
400
-
401
- STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
621
+
402
-
403
-
404
-
405
- MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
406
-
407
- MEDIA_URL = '/media/'
408
-
409
-
410
-
411
-
412
-
413
- """
414
-
415
- # heroku用
416
-
417
- try:
418
-
419
- from .local_settings import *
420
-
421
- except ImportError:
422
-
423
- pass
424
-
425
- """
426
-
427
- if not DEBUG:
428
-
429
- import django_heroku
430
-
431
- django_heroku.settings(locals())
432
-
433
- import dj_database_url
434
-
435
- DATABASES['default'] = dj_database_url.config()
436
-
437
- DATABASES['default']['ENGINE'] = 'django.contrib.gis.db.backends.postgis'
438
-
439
- GDAL_LIBRARY_PATH = os.getenv('GDAL_LIBRARY_PATH')
440
-
441
- GEOS_LIBRARY_PATH = os.getenv('GEOS_LIBRARY_PATH')
442
-
443
- # ~heroku用
444
622
 
445
623
  ```
446
624
 
625
+ ```tree
626
+
627
+ C:.
628
+
629
+ ├─deploy
630
+
631
+ | ├─__init.py
632
+
633
+ | ├─asgi.py
634
+
635
+ | ├─local_settings.py
636
+
637
+ | ├─settings.py
638
+
639
+ | ├─urls.py
640
+
641
+ | ├─wsgi.py
642
+
643
+ ├─map
644
+
645
+ │ ├─data
646
+
647
+ │ ├─migrations
648
+
649
+ │ ├─static
650
+
651
+ │ │ └─map
652
+
653
+ │ │ ├─css
654
+
655
+ │ │ └─js
656
+
657
+ │ ├─templates
658
+
659
+ │ │ ├─map
660
+
661
+ | | | ├─index.html
662
+
663
+ | | | ├─upload.html
664
+
665
+ │ │ └─registration
666
+
667
+ | | | └─login.html
668
+
669
+ ├─media
670
+
671
+ │ └─image
672
+
673
+ ├─static
674
+
675
+ ├─staticfiles
676
+
677
+ │ ├─admin
678
+
679
+ │ ├─gis
680
+
681
+ │ ├─leaflet
682
+
683
+ │ ├─map
684
+
685
+ │ └─rest_framework
686
+
687
+ ├─__init__.py
688
+
689
+ ├─manage.py
690
+
447
- ```procfile
691
+ ├─Procfile
448
-
692
+
449
- web: gunicorn geodj.wsgi --log-file -
693
+ ├─requirements.txt
694
+
695
+ ├─runtime.txt
696
+
697
+ └─.gitignore
450
698
 
451
699
  ```
452
700
 
453
- requirements.txt
701
+
454
-
455
- ```requirements
702
+
456
-
457
- asgiref==3.2.9
703
+
458
-
459
- brotlipy==0.7.0
460
-
461
- certifi==2020.6.20
462
-
463
- cffi==1.14.0
464
-
465
- chardet==3.0.4
466
-
467
- cryptography==2.9.2
468
-
469
- dj-database-url==0.5.0
470
-
471
- Django==3.0.7
472
-
473
- django-cleanup==5.1.0
474
-
475
- django-cors-headers==3.2.1
476
-
477
- django-filter==2.3.0
478
-
479
- django-heroku==0.3.1
480
-
481
- django-leaflet==0.27.1
482
-
483
- djangorestframework==3.11.0
484
-
485
- djangorestframework-gis==0.15
486
-
487
- fastcache==1.1.0
488
-
489
- future==0.18.2
490
-
491
- glob2==0.7
492
-
493
- gunicorn==20.0.4
494
-
495
- idna==2.9
496
-
497
- importlib-metadata==1.6.1
498
-
499
- Markdown==3.2.2
500
-
501
- mpmath==1.1.0
502
-
503
- olefile==0.46
504
-
505
- Pillow==7.2.0
506
-
507
- psycopg2==2.8.5
508
-
509
- psycopg2-binary==2.8.6
510
-
511
- pycparser==2.20
512
-
513
- pyOpenSSL==19.1.0
514
-
515
- PySocks==1.7.1
516
-
517
- pytz==2020.1
518
-
519
- requests==2.24.0
520
-
521
- six==1.14.0
522
-
523
- sqlparse==0.3.1
524
-
525
- sympy==1.6.2
526
-
527
- urllib3==1.25.9
528
-
529
- whitenoise==5.2.0
530
-
531
- win-inet-pton==1.1.0
532
-
533
- wincertstore==0.2
534
-
535
- zipp==3.1.0
536
-
537
- ```
538
-
539
- wsgi.py
540
-
541
- ```wsgi
542
-
543
- """
544
-
545
- WSGI config for geodj project.
546
-
547
-
548
-
549
- It exposes the WSGI callable as a module-level variable named ``application``.
550
-
551
-
552
-
553
- For more information on this file, see
554
-
555
- https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/
556
-
557
- """
558
-
559
-
560
-
561
- import os
562
-
563
- from django.core.wsgi import get_wsgi_application
564
-
565
-
566
-
567
- os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'geodj.settings')
568
-
569
-
570
-
571
- application = get_wsgi_application()
572
-
573
- ```
574
-
575
- ### 試したこと
576
-
577
- heroku run python manage.py checkしても
578
-
579
- System check identified no issues (0 silenced).となり問題なさそうです。
580
-
581
-
582
-
583
- djangoアプリを作り直してみましたが、500になってしまう。
584
-
585
- 何か根本的に間違っているんでしょうか?
586
704
 
587
705
  ### 補足情報(FW/ツールのバージョンなど)
588
706
 

1

追加

2020/11/24 01:40

投稿

yamatar
yamatar

スコア4

test CHANGED
File without changes
test CHANGED
@@ -392,9 +392,9 @@
392
392
 
393
393
  STATIC_URL = '/static/'
394
394
 
395
- STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')#元はstatic
395
+ STATIC_ROOT = os.path.join(BASE_DIR, 'static')
396
-
396
+
397
- STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)#元はmap/atatic
397
+ STATICFILES_DIRS = (os.path.join(BASE_DIR, 'map/static'),)
398
398
 
399
399
  # ↓ heroku追加
400
400
 
@@ -580,6 +580,10 @@
580
580
 
581
581
 
582
582
 
583
+ djangoアプリを作り直してみましたが、500になってしまう。
584
+
585
+ 何か根本的に間違っているんでしょうか?
586
+
583
587
  ### 補足情報(FW/ツールのバージョンなど)
584
588
 
585
589
  windows10