The current path, auth/, didn't match any of these - django

I am trying to setup url dispatcher in my project. I have project with follwing structure
forecast
|___ forecast
|_______ __init__.py
|_______ settings.py
|_______ urls.py
|_______ wsgi.py
|____authorization
|_______ apps.py
|_______ urls.py
|_______ models.py
|_______ views.py
|___ templates
|_______ registration
|____________ login.html
In my forecast/urls.py i put logic of
from django.contrib import admin
from django.urls import path,include
urlpatterns = [
path('admin/', admin.site.urls),
path('',include('main.urls')),
path('auth',
include('authorization.urls')),
]
The main point for my question is path('auth',include('authorization.urls')) i include urls.py from authorization/ and in this urls.py i want to put all logic for authorization of my project like login page
registration page reset_password page i have the following code in authorization/urls.py
from django.urls import path
from . import views
urlpatterns =[
path('registration',
views.registration_form),
path('login',
views.login_name),
]
My registration_form view is
from django.shortcuts import render
def registration_form(request):
return
render(request,'registration/login.html',{})
For output my logic on front-end side i created in my project templates directory and inside it registration directory and inside it i put login.html file. in settings.py i have
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'dataflow',
'authorization',
'main',
'django.contrib.postgres',
]
TEMPLATES = [{
'DIRS':
[os.path.join(BASE_DIR,'templates')],
}]
. Than after running server and opened http://127.0.0.1:8000/auth/registration but django erised page not found exception.Can anyone guide me where is error occured???

Are you sure you included this segment in your settings.py ?
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
...
'authorization.apps.AuthorizationConfig', // add this manually
]
The point is that, whenever you create an app, Django will not automatically register it as a part of the framework.

Related

Adding an aliasName for url name app django

In a django project, I have an app : app_signup.
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'app_signup',
app_signup/urls.py
from django.urls import path, include
from . import views
urlpatterns = [
path('',views.index, name='index'),
]
Is it possible to add an alias to the app in order to see the alias (http://localhost:8000/alias/) instead of the name of the app(http://localhost:8000/app_signup/) in the url on the browser.
The name of the app in INSTALLED_APPS doesn't really matter. Your project's main urls.py file is the one that specifies the path. There when constructing the urlpatterns list, you can do path('alias/', include('app_signup.urls')) instead of path('app_signup/', include('app_signup.urls')).
As far as I understand from the example you added, you are editing the urls.py file within the app you created. Not your app, but directly in the project file (in the same directory as settings.py), urls.py probably as path('app_signup/', include('app_signup.urls')) as mentioned in the answer above. This is the urls.py you need to edit.

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)

ModuleNotFoundError: No module named 'polls'

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

how to use django markdown in my blog

at first I successfully install django markdown
pip install django-markdown
than I add django-markdown in my setting.py file
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'blog',
'django-markdown',
]
then, I change my urls.py like as:
from django.conf.urls import include, url
from django.contrib import admin
from resume import views
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^home/$', views.home, name='home'),
url(r'^blog/', include('blog.urls',namespace='blog',app_name='blog')),
url('^markdown/', include('django_markdown.urls')),
]
I also change my admin.py file like as:
from django.contrib import admin
from .models import Post
from django_markdown.admin import MarkdownModelAdmin
class PostAdmin(admin.ModelAdmin):
list_display = ('title','slug','author','publish','status')
list_filter = ('status','created','publish','author')
search_fields = ('title','body')
prepopulated_fields = {'slug':('title',)}
raw_id_fields = ('author',)
date_hierarchy = 'publish'
ordering = ['status','publish']
# Register your models here.
admin.site.register(Post,MarkdownModelAdmin, PostAdmin)
but, when I start my runserver, django gives me an error like this:
ModuleNotFoundError: No module named 'django-markdown'
how can i solve my problem?
In installed apps you should add django_markdown instead of django-markdown

Django Basics myapp mapping in myproject "myapp" is not defined

I am learning django, and have ran python manage.py startapp myapp which created the following folder structure:
myapp/
__init__.py
admin.py
models.py
tests.py
views.py
I also added myapp to INSTALLED_APPS in settings,
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'myapp',
)
then I ran python manage.py migrate and python manage.py createsuperuser to create super user
I have also created views of myapp :
"from django.http import HttpResponse
def hello(request):
text = """<h1>welcome to my app !</h1>"""
return HttpResponse(text)
"
Finally, here's the URL mapping:
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin', include(admin.site.urls)),
url(r'^hello/', 'myapp.views.hello', name = 'hello'),
)
When ran, it throws an error stating that "myapp" is not defined. And I am not able to access admin page at http://127.0.0.1:8000/admin
How can I solve this error and get my application to work?
Possibly myapp is not included in INSTALLED_APPS in setting.py. I suppose you are following this tutorial.
add this in your url mapping:
from myapp import views