###前提・実現したいこと
ブラウザに指定した画像を表示させたいです。
※画像は「cards」というフォルダの「C_01.png」です。
###発生している問題・エラーメッセージ
http://127.0.0.1:8000/firstApp/hello/ とURL欄に打ち込むと、「このサイトにアクセスできません」となる。
###該当のソースコード
【firstDjango\firstApp\templates\card.html】
{% load staticfiles %} <!DOCTYPE html> <html lang = "ja"> <head> <meta charset = "UTF-8"> <title>トランプ</title> </head> <body> <img src = "{% static 'cards/C_01.png' %}"> </body> </html>
【firstDjango\firstDjango\settings.py】
""" Django settings for firstDjango project. Generated by 'django-admin startproject' using Django 1.10. For more information on this file, see https://docs.djangoproject.com/en/1.10/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/1.10/ref/settings/ """ import os # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = '*e2!*^^$@op8tphs5!zy+ip(xg*5^j-6!276$bcemkgka5$)&a' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = [ 'firstApp' 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', ] MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] ROOT_URLCONF = 'firstDjango.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ] WSGI_APPLICATION = 'firstDjango.wsgi.application' # Database # https://docs.djangoproject.com/en/1.10/ref/settings/#databases DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), } } # Password validation # https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ { 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', }, { 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', }, { 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', }, { 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', }, ] # Internationalization # https://docs.djangoproject.com/en/1.10/topics/i18n/ LANGUAGE_CODE = 'en-us' TIME_ZONE = 'UTC' USE_I18N = True USE_L10N = True USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/1.10/howto/static-files/ STATIC_URL = '/static/'
【firstDjango\firstApp\views.py】
from django.shortcuts import render from django.http import HttpResponse # Create your views here. def hello(request): return HttpResponse('こんにちは') def card(request): return render(request, 'card.html') #from django.shortcuts import render #from django.http import HttpResponse # Create your views here. #def edit(request): #return HttpResponse('編集') #def show(request): #return HttpResponse('読む')
【firstDjango\firstApp\urls.py】
from django.conf.urls import url from . import views urlpatterns = [url(r'^hello/$',views.hello), url(r'^card/$', views.card), ] #!coding:utf-8 #from django.conf.urls import patterns, url #from blog import views #urlpatterns = patterns('', #url(r'^$', views.show, name='show'), #url(r'^edit/$', views.edit, name='edit'), #)
###試したこと
「http://127.0.0.1:8000/firstApp/hello/」を打ち込む前に、コマンドプロンプトで「python manage.py runserver」を一度行いました。
下記、実行結果となります。
###補足情報(言語/FW/ツール等のバージョンなど)
windows8.1
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。