import views method in urls.py file like this:
29 Ekim 2017 Pazar 23:39:12 UTC+3 tarihinde Andre Basel yazdı:
-- from django.conf.urls import url
from django.contrib import admin
from django.contrib import admin
from yourapp.views import hello # <<<<<<
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^hello/$', hello),
]
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^hello/$', hello),
]
29 Ekim 2017 Pazar 23:39:12 UTC+3 tarihinde Andre Basel yazdı:
I am totally new to Django, and working through the following tutorial https://djangobook.com/views-urlconfs/
Ihavecreatddf the following view in views.py
from django.http import HttpResponse
def hello(request):
return HttpResponse("Hello world")
And then as per the tutorial updated urls.py as follows:
from django.conf.urls import url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^hello/$', hello),
]
When I try an browse http://127.0.0.1:8000/ I now no can no longer connect and the console shows the following error.
System check identified no issues (0 silenced).
October 29, 2017 - 20:14:10
Django version 1.11.6, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[29/Oct/2017 20:14:14] "GET / HTTP/1.1" 200 1716
Performing system checks...
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f1eae0c4268>
Traceback (most recent call last):
File "/home/abasel/Dajango_Projects/my_first_project/ , line 228, in wrapperproject_venv/lib64/python3.6/ site-packages/django/utils/ autoreload.py"
fn(*args, **kwargs)
File "/home/abasel/Dajango_Projects/my_first_project/ , line 125, in inner_runproject_venv/lib64/python3.6/ site-packages/django/core/ management/commands/runserver. py"
self.check(display_num_errors=True )
File "/home/abasel/Dajango_Projects/my_first_project/ , line 359, in checkproject_venv/lib64/python3.6/ site-packages/django/core/ management/base.py"
include_deployment_checks=include_deployment_checks ,
File "/home/abasel/Dajango_Projects/my_first_project/ , line 346, in _run_checksproject_venv/lib64/python3.6/ site-packages/django/core/ management/base.py"
return checks.run_checks(**kwargs)
File "/home/abasel/Dajango_Projects/my_first_project/ , line 81, in run_checksproject_venv/lib64/python3.6/ site-packages/django/core/ checks/registry.py"
new_errors = check(app_configs=app_configs)
File "/home/abasel/Dajango_Projects/my_first_project/ , line 16, in check_url_configproject_venv/lib64/python3.6/ site-packages/django/core/ checks/urls.py"
return check_resolver(resolver)
File "/home/abasel/Dajango_Projects/my_first_project/ , line 26, in check_resolverproject_venv/lib64/python3.6/ site-packages/django/core/ checks/urls.py"
return check_method()
File "/home/abasel/Dajango_Projects/my_first_project/ , line 254, in checkproject_venv/lib64/python3.6/ site-packages/django/urls/ resolvers.py"
for pattern in self.url_patterns:
File "/home/abasel/Dajango_Projects/my_first_project/ , line 35, in __get__project_venv/lib64/python3.6/ site-packages/django/utils/ functional.py"
res = instance.__dict__[self.name] = self.func(instance)
File "/home/abasel/Dajango_Projects/my_first_project/ , line 405, in url_patternsproject_venv/lib64/python3.6/ site-packages/django/urls/ resolvers.py"
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/abasel/Dajango_Projects/my_first_project/ , line 35, in __get__project_venv/lib64/python3.6/ site-packages/django/utils/ functional.py"
res = instance.__dict__[self.name] = self.func(instance)
File "/home/abasel/Dajango_Projects/my_first_project/ , line 398, in urlconf_moduleproject_venv/lib64/python3.6/ site-packages/django/urls/ resolvers.py"
return import_module(self.urlconf_name )
File "/usr/lib64/python3.6/importlib/__init__.py" , line 126, in import_module
return _bootstrap._gcd_import(name[level :], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap_external>" , line 678, in exec_module
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
File "/home/abasel/Dajango_Projects/my_first_project/ , line 21, in <module>mysite/mysite/urls.py"
url(r'^hello/$', hello),
NameError: name 'hello' is not defined
I am not sure how to proceed.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d6572a7d-2d10-4ab8-81ed-d4157fe94f27%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment