I am getting errors in almost all imports please help.
i'm using django 2.2.5, python 3.7, but getting errors in unresolved import'django.contrib' ,unresolved import'django.urls',unresolved import'django.shortcuts' etc
from django.contrib import admin
from django.urls import path,include
urlpatterns = [
path("", include("hello.urls")),
path('admin/', admin.site.urls),
]
from django.shortcuts import render
from django.http import HttpResponse
def home(request):
return HttpResponse("Hello, Django!")
Message=No module named 'django'
File "C:\Users\Sharf\Desktop\python projects\p1\calc\urls.py", line 1,
in <module>
from django.urls import path
Can you post your settings.py file ? I think the problem comes from here ...
INSTALLED_APPS = [
'mainApp.apps.nameApp',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'channels'
]
ROOT_URLCONF = 'app.urls'
Related
urls.py
from django.contrib import admin
from django.urls import path, include
from blocktunes import views #error in blocktunes
urlpatterns = [
path('', include('blocktunes.urls')),
path('admin/', admin.site.urls),
path('', views.UserRegister_view)
]
Why is it showing missing imports?
settings.py
INSTALLED_APPS = [
'blocktunes.apps.blocktunesConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
PLEASE HELP.
Image link of structure of apps
[1]: https://i.stack.imgur.com/YhPEg.png
By adding the following command in .vscode of the folder, I was able to import blocktunes.
"python.analysis.extraPaths": ["./etherly"]
from django.http import HttpResponse
from django.shortcuts import render
# Create your views here.
def index(request):
return HttpResponse("Hellow, World !")
from django.urls import path
from . import views
urlspattern=[
path("",views.index,name="index")
]
from django.contrib import admin
from django.urls import include,path
urlpatterns = [
path('admin/', admin.site.urls),
path("hello/", include("hello.urls"))
]
INSTALLED_APPS = [
'hello',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
Error I am gettting is
Using the URLconf defined in helloproject.urls, Django tried these URL patterns, in this order:
admin/
The current path, hello/, didn't match any of these.
you have a typo error on urlpattern
urlspattern=[
path("",views.index,name="index")
]
you have to change that to
urlpatterns=[
path("",views.index,name="index")
]
In this line change urlpattern to urlpatterns
urlpatterns=[
path("",views.index,name="index")
]
I have created a directory called vsdk which includes service_development (a voice application) and my newly created application called dashboard. Unfortunately I can’t seem to get the main page of dashboard to work. I get a 404 error when trying to access 127.0.0.1:8000/dashboard/, while doing everything similar to what I’ve done with service_development.
Would someone be able to help me?
Vsdk\settings.py
INSTALLED_APPS = [
'vsdk.service_development.apps.ServiceDevelopmentConfig',
'vsdk.dashboard.apps.DashboardConfig',
'storages',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
Vsdk\dashboard\apps.py
from django.apps import AppConfig
from django.utils.translation import ugettext_lazy as _
class DashboardConfig(AppConfig):
name = 'vsdk.dashboard'
verbose_name = _("Dashboards")
Vsdk\urls.py
from django.conf.urls import url, include
from django.contrib import admin
from django.conf.urls.static import static
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
from django.urls import include, path
admin.site.site_header = _("Petrichor Rain Service")
urlpatterns = [
url(r'^', admin.site.urls),
url(r'^vxml/', include('vsdk.service_development.urls')),
url(r'^vxml/', include('vsdk.dashboard.urls')),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Vsdk\dashboard\urls.py
from django.shortcuts import render
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
I am trying to wire up a view based on the Django tutorial (1.8), and am for some reason not getting a basic url to work:
Page not found (404)
Settings
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'events',
)
In the main folder, I have these_events/these_events/urls.py
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^/', include('events.urls')),
]
In the events app, I have these_events/events/urls.py
from django.conf.urls import url
from . import views
urlpatterns = [
url(r"^$", views.search_db, name='search-db')
]
these_events/events/views.py:
from django.shortcuts import render
from django.http import HttpResponse
def search_db(request):
return HttpResponse("hello, world")
This has me befuddled as I followed the example, and this is the way I remember using Django in the past.
In these_events/these_events/urls.py
try changing
url(r'^/', include('events.urls')),
to
url(r'', include('events.urls')),
I have a an unresolved URL request and Not quite sure what's causing the issue.
I am setting a homepage on my application for context
My view in views.py:
from django.http import HttpResponse
from django.shortcuts import render
def home(request):
return render(request, "homepage template.html")
My URL in urls.py:
from django.conf.urls import patterns, include, url
from django.contrib import admin
urlpatterns = patterns('',
# Examples:
url(r'^$', 'homepage.views.home'),
enter code here
The error given in browser:
No module named 'homepage'
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.7.5
Exception Type: ImportError
Exception Value:
No module named 'homepage'
Exception Location: C:\Python34\lib\importlib\__init__.py in import_module, line 109
Python Executable: C:\Python34\python.exe
Python Version: 3.4.3
Python Path:
['C:\\Users\\jodie\\Desktop\\NtokloMH',
'C:\\Windows\\SYSTEM32\\python34.zip',
'C:\\Python34\\DLLs',
'C:\\Python34\\lib',
'C:\\Python34',
'C:\\Python34\\lib\\site-packages']
Server time: Sat, 7 Mar 2015 19:10:33 +0000
I thought I defined the module through the views.py and urls.py code, but pycharm is telling me it cannot resolve the URL.
As requested:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'musicsearch',
)
If musicsearch is your only installed application that you made yourself in django, and the views.py file is in that directory, then
urlpatterns = patterns('',
# Examples:
url(r'^$', 'homepage.views.home'),
enter code here
should be
urlpatterns = patterns('',
# Examples:
url(r'^$', 'musicsearch.views.home'),
enter code here
Otherwise, if homepage is an application that does exist, you need to add it to INSTALLED_APPS as such:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'musicsearch',
'homepage',
)