前提・実現したいこと
Helloworldと表示させるプログラムをつくりたい
発生している問題・エラーメッセージ
projectのファイル内に移動して python manage.py runserver
を実行すると次のエラーがでる
Unhandled exception in thread started by <function wrapper at 0x7f14e9951d50> Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/django/utils/autoreload.py", line 228, in wrapper fn(*args, **kwargs) File "/usr/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 124, in inner_run self.check(display_num_errors=True) File "/usr/lib/python2.7/dist-packages/django/core/management/base.py", line 359, in check include_deployment_checks=include_deployment_checks, File "/usr/lib/python2.7/dist-packages/django/core/management/base.py", line 346, in _run_checks return checks.run_checks(**kwargs) File "/usr/lib/python2.7/dist-packages/django/core/checks/registry.py", line 81, in run_checks new_errors = check(app_configs=app_configs) File "/usr/lib/python2.7/dist-packages/django/core/checks/urls.py", line 16, in check_url_config return check_resolver(resolver) File "/usr/lib/python2.7/dist-packages/django/core/checks/urls.py", line 26, in check_resolver return check_method() File "/usr/lib/python2.7/dist-packages/django/urls/resolvers.py", line 256, in check for pattern in self.url_patterns: File "/usr/lib/python2.7/dist-packages/django/utils/functional.py", line 35, in __get__ res = instance.__dict__[self.name] = self.func(instance) File "/usr/lib/python2.7/dist-packages/django/urls/resolvers.py", line 407, in url_patterns patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) File "/usr/lib/python2.7/dist-packages/django/utils/functional.py", line 35, in __get__ res = instance.__dict__[self.name] = self.func(instance) File "/usr/lib/python2.7/dist-packages/django/urls/resolvers.py", line 400, in urlconf_module return import_module(self.urlconf_name) File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module __import__(name) File "/mnt/c/Users/user/Documents/Python Scripts/Django/helloworld/helloworldproject/helloworldproject/urls.py", line 18, in <module> from views import helloworldfunction ImportError: cannot import name helloworldfunction
ソースコード
1.urls.py """helloworldproject URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/1.11/topics/http/urls/ Examples: Function views 1. Add an import: from my_app import views 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') Class-based views 1. Add an import: from other_app.views import Home 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') Including another URLconf 1. Import the include() function: from django.conf.urls import url, include 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) """ from django.conf.urls import url from django.contrib import admin from views import helloworldfunction urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^helloworld/', helloworldfunction) ] ############## 2.viwes.py from django.http import HttpResponse def helloworldfunction(request): returnobject = HttpResponse("hello world") return returnobject
試したこと
スペルミスがないかどうか確認をした
補足情報(FW/ツールのバージョンなど)
VSCodeで実行している
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。