ModuleNotFoundError: No module named 'polls' - django

I am following the official Django tutorial on https://docs.djangoproject.com/en/2.2/intro/tutorial01/ but somehow I am not able to run the server as I have created the polls app and added the required urls. When I use the command "py mysite\manage.py runserver" it returns me ModuleNotFoundError: No module named 'polls' error.
Project Folder available at
https://i.stack.imgur.com/bbxfW.png
#views.py
from django.http import HttpResponse
def index(request):
return HttpResponse('<h1><this is a test page</h1>')
#urls.py in polls
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
#urls.py in mysite\mysite
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('polls/', include('polls.urls')),
path('admin/', admin.site.urls),
]
#settings.py
INSTALLED_APPS = [
'polls',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
[1]: https://i.stack.imgur.com/bbxfW.png

Well, I resolved it myself. Polls module was not found because it was created outside the project directory. When I removed it and recreated inside the project directory, it was OK now.

also it may be a good idea to cd into yoru django project so you are only running
python manage.py runserver

Related

manage.py cant find any urls in myapp.urls file. Says something about circular import

I seem to find the following error despite making a number of changes in my app.urls file and in my project.urls file. I can't seem to put my finger on it, here is the code:
app.urls file
from django.urls import path
from . import views
urlpatterns = [
path('', views.home_page, name = 'home_page'),
]
project.urls file
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('Success.urls')),
]
views.py file
from django.shortcuts import render
from django.http import HttpResponse
enter code here
Create your views here.
def home_page(request):
hello = 'hello world'
return HttpResponse (hello)
Have you added your app in the settings.py file?
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'Success',
]
i imported render and used it instead i can't figure out though why it worked
views.py file
from django.shortcuts import render
def hello_world(request):
return render(request, 'hello_world.html')
app/urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.hello_world, name = 'hello_world')
]
project/urls.py
from django.contribs import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('app.urls'))
]

Django Oscar Dashboard link not accessible

I have developed oscar /django applications before but I am completely stumped by this issue:
I can see the dashboard url in the supported urls list but I am not able to access it.
404 Page
I have forked a few apps from oscar like voucher, shipping, checkout, reviews and customized them in various ways(None of these are dashboard related) . This is my INSTALLED_APPS:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'django.contrib.flatpages',
'oscar.config.Shop',
'oscar.apps.analytics.apps.AnalyticsConfig',
'iirns.checkout.apps.CheckoutConfig',
'oscar.apps.address.apps.AddressConfig',
'iirns.shipping.apps.ShippingConfig',
'oscar.apps.catalogue.apps.CatalogueConfig',
'iirns.catalogue.reviews.apps.CatalogueReviewsConfig',
'oscar.apps.communication.apps.CommunicationConfig',
'oscar.apps.partner.apps.PartnerConfig',
'oscar.apps.basket.apps.BasketConfig',
'iirns.payment.apps.PaymentConfig',
'oscar.apps.offer.apps.OfferConfig',
'oscar.apps.order.apps.OrderConfig',
'oscar.apps.customer.apps.CustomerConfig',
'oscar.apps.search.apps.SearchConfig',
'iirns.voucher.apps.VoucherConfig',
'oscar.apps.wishlists.apps.WishlistsConfig',
'oscar.apps.dashboard.apps.DashboardConfig',
'oscar.apps.dashboard.reports.apps.ReportsDashboardConfig',
'oscar.apps.dashboard.users.apps.UsersDashboardConfig',
'oscar.apps.dashboard.orders.apps.OrdersDashboardConfig',
'oscar.apps.dashboard.catalogue.apps.CatalogueDashboardConfig',
'oscar.apps.dashboard.offers.apps.OffersDashboardConfig',
'oscar.apps.dashboard.partners.apps.PartnersDashboardConfig',
'oscar.apps.dashboard.pages.apps.PagesDashboardConfig',
'oscar.apps.dashboard.ranges.apps.RangesDashboardConfig',
'oscar.apps.dashboard.reviews.apps.ReviewsDashboardConfig',
'oscar.apps.dashboard.vouchers.apps.VouchersDashboardConfig',
'oscar.apps.dashboard.communications.apps.CommunicationsDashboardConfig',
'oscar.apps.dashboard.shipping.apps.ShippingDashboardConfig',
# 3rd-party apps that oscar depends on
'widget_tweaks',
'haystack',
'treebeard',
'sorl.thumbnail',
'django_tables2',
'mailer',
'extra',
]
and this is my root url file:
from django.conf.urls import url
from django.contrib import admin
from django.apps import apps
from django.urls import include, path
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('',include('extra.urls')),
path('', include(apps.get_app_config('oscar').urls[0])),
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

How do I remove 404 error from Django app?

I am trying to create a web app using Django framework. I followed the tutorial and did everything as per the tutorial.
DJANGO_PROJECT:
from django.contrib import admin
from django.urls import include
from django.conf.urls import url
urlpatterns = [
url(r'^dellserver/', include('dellserver.urls')),
url(r'^admin/', admin.site.urls),
]
Settings.py:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'dellserver'
]
dellserver\urls.py:
from . import views
from django.conf.urls import url
urlpatterns = [
url(r'^dellserver/$', views.index, name="index")
]
views.py:
from django.http import HttpResponse
def index(request):
return HttpResponse("<h1>Hello World</h1>")
Can anybody tell me what I am doing wrong? Why I a getting the **
Page not found (404)
**
You did the mistake in project's url (folder which include settings.py file)
from django.contrib import admin
from django.urls import include
from django.conf.urls import url
urlpatterns = [
url(r'^/', include('dellserver.urls')), # this line you did the Mistake
url(r'^admin/', admin.site.urls),
]
in main urls remove dellserver as shown below.
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^', include('dellserver.urls')),
]
so that you can call your url ../dellserver/, otherwise you have to call it ../dellserver/dellserver twice.

Using the URLconf defined in chatbottest.urls

I use Pycharm,django2.0.4
I started Django yesterday.
I faced one error.
Using the URLconf defined in chatbottest.urls, Django tried these URL patterns, in this order:
1. admin/
2. globalHaksik/
The empty path didn't match any of these.
enter image description here
setting.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'globalHaksik',
]
chatbottest\urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('globalHaksik/', include('globalHaksik.urls')),
]
globalHaksik\urls.py
from django.urls import path
from . import views
urlpatterns = [
path('keyboard/', views.keyboard),
]
views.py
from django.http import JsonResponse
def keyboard(request):
return JsonResponse({
'type': 'buttons',
'buttons': ['학식', '배달음식']
})
I do not know the correct answer if I look for the same error on this site.
Please kindly answer me.
Update: Looks like you are just trying to access the URL leading to views.keyboard. So the url that you need to access is /globalHaksik/keyboard/ (and not just /keyboard) since the path defined in chatbottest\urls.py has globalHaksik/ in it:
path('globalHaksik/', include('globalHaksik.urls')),
If you are trying to access /, then you need to add the empty pattern as follows:
chatbottest\urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('', views.your_view_name),
path('admin/', admin.site.urls),
path('globalHaksik/', include('globalHaksik.urls')),
]
If you are trying to access /globalHaksik/, then you you need to add the empty pattern to globalHaksik\urls.py:
globalHaksik\urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.your_view_name),
path('keyboard/', views.keyboard),
]

Using the URLconf defined in TEST_PAGE, Django tried these URL patterns, in this order:

I've reviewed other posts related to my question, but I'm unable to find an answer for my question.
When I try to access "http://127.0.0.1:8000/TEST_PAGE" I get the following error:
"Using the URLconf defined in TEST_PAGE, Django tried these URL patterns, in this order:
^admin/
^$
^TEST_PAGE/
The current URL, TEST_PAGE, didn't match any of these."
Here is what I have for Mysite/Mysite/urls.py:
from django.conf.urls import url, include
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', include('Main_Page.urls')),
url(r'^TEST_PAGE/', include('TEST_PAGE')),
]
I have the APP installed in Mysite/Mysite/settings.py:
INSTALLED_APPS = [
'TEST_PAGE',
'Main_Page',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
Here is what I have for Mysite/TEST_PAGE/urls.py:
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^TEST_PAGE', views.index, name='TEST_PAGE'),
]
And here is what I have for Mysite/TEST_PAGE/views.py:
from django.shortcuts import render
def index(request):
return render(request, 'TEST_PAGE/TEST_PAGE.html')
The main/index/home app works fine, I'm just trying to access the second app.
I'm new to this, so any help would be appreciated.
By including 'TEST_PAGE' twice(in both urls.py), you have defined a url:
/TEST_PAGE/TEST_PAGE
So
django can find url /TEST_PAGE/TEST_PAGE but not /TEST_PAGE
Your Mysite/TEST_PAGE/urls.py should be:
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='TEST_PAGE'), # maps to /TEST_PAGE/
]