B
B
blizzard2018-02-26 22:12:13
Django
blizzard, 2018-02-26 22:12:13

Why does the error "ImportError: No module named" appear?

there is this in the views.py file:

import _datetime
from django.http import HttpResponse
def cur_time():
    now = _datetime.datetime.now()
    html = "<html><body>It is now %s.</body></html>" % now
    return HttpResponse(html)

In the urls.py file, I'm trying to bind the view to the url:
from django.contrib import admin
from django.urls import path

from cyberfight.mainpage import views

urlpatterns = [
    path('admin/', admin.site.urls),
    path('index/', views.cur_time())
]

In terminal after python3 manage.py runserver:
File "/home/dimaseg/PycharmProjects/cyberfight.ru/cyberfight/cyberfight/urls.py", line 19, in <module>
    from cyberfight.mainpage import views
ImportError: No module named 'cyberfight.mainpage'

What's wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Web Dentist, 2018-02-26
@s41blizzard

from . import views

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question