Sunday, October 29, 2017

Re: Following tutoria: View not defined

Okkk. From your url pattern, What you should do is http://127.0.0.1:8000/hello. Because your url pattern says r'^hello/$'

But what u are doing presently is 


In this case your url pattern is supposed to be r'^$' and not r'^hello/$'


Yingi Kem

On 29 Oct 2017, at 10:51 PM, Andre Basel <andre.basel@gmail.com> wrote:

Hi all

I see that I missed the import.

I now have
from django.conf.urls import url
from django.contrib import admin

from mysite.views import hello

urlpatterns
= [
    url
(r'^admin/', admin.site.urls),
    url
(r'^hello/$', hello),
]


But get the following error in my browser now
Page not found (404)
Request Method:GET
Request URL:http://127.0.0.1:8000/
      Using the URLconf defined in mysite.urls,

      Django tried these URL patterns, in this order:

  1. ^admin/
                   
  2. ^hello/$

        The empty path didn't match any of these


      You're seeing this error because you have DEBUG = True in
      your
Django settings file. Change that to False, and Django
      will display a standard
404 page.
   




On Monday, October 30, 2017 at 10:29:36 AM UTC+13, Oğuzhan Arslan wrote:
import views method in urls.py file like this:


from django.conf.urls import url
from django.contrib import admin

from yourapp.views import 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/project_venv/lib64/python3.6/site-packages/django/utils/autoreload.py", line 228, in wrapper
    fn
(*args, **kwargs)
 
File "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/management/commands/runserver.py", line 125, in inner_run
   
self.check(display_num_errors=True)
 
File "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/management/base.py", line 359, in check
    include_deployment_checks
=include_deployment_checks,
 
File "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/management/base.py", line 346, in _run_checks
   
return checks.run_checks(**kwargs)
 
File "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/checks/registry.py", line 81, in run_checks
    new_errors
= check(app_configs=app_configs)
 
File "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/checks/urls.py", line 16, in check_url_config
   
return check_resolver(resolver)
 
File "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/core/checks/urls.py", line 26, in check_resolver
   
return check_method()
 
File "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/urls/resolvers.py", line 254, in check
   
for pattern in self.url_patterns:
 
File "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/utils/functional.py", line 35, in __get__
    res
= instance.__dict__[self.name] = self.func(instance)
 
File "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/urls/resolvers.py", line 405, in url_patterns
    patterns
= getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
 
File "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/utils/functional.py", line 35, in __get__
    res
= instance.__dict__[self.name] = self.func(instance)
 
File "/home/abasel/Dajango_Projects/my_first_project/project_venv/lib64/python3.6/site-packages/django/urls/resolvers.py", line 398, in urlconf_module
   
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/mysite/mysite/urls.py", line 21, in <module>
    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/b6107382-640f-4bf2-89bc-586e86531d57%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment