I'm new with Django Framework, I've been following few tutorials and trying to create a website using Django 3.0.1 and Pythong 3.8
when I crate my super user using:
python manage.py createsuperuser
I'm able to setup it up, but when I try to access: 'http://127.0.0.1:8000/admin/'
Server can't be accessed(image)
This only happens when attempting to access after entering my username and passwords, as soon as I enter my credentials, the server stops.
This is what my urls.py under the project looks like:
from django.contrib import admin from django.urls import path, include
admin.autodiscover()
urlpatterns = [
path('admin/', admin.site.urls),
path('tokens/', include('tokens.urls')) ]
Does someone have an Idea of what the problem is?
Thank you in Advance.
Related
I'm new to Django/Python. I'm currently taking a beginners course and I'm having difficulty setting up my URLs and connecting to a local server. I'm using Python version: 3.7.0 and Django v.2
The command line does not give any errors (0), it tells me to go here:
Starting development server at http://127.0.0.1:8000/
Which I believe is the local host, however the site says
This site can’t be reached
127.0.0.1 refused to connect.
Can anyone let me know what I'm missing I would greatly appreciate it so that I can continue on with my studying. I'm using tutorials on YT Django Tutorial and the guy is using an older Django so I think that may be why I'm having trouble. He says we should still be okay to follow through even on the new version of Django.
urls.py
from django.contrib import admin
from django.urls import path
from.import views
urlpatterns = [
path('', views.homepage),
path('admin/', admin.site.urls),
path('about/', views.about),
]
views.py
from django.http import HttpResponse
def homepage(request):
return HttpResponse('homepage')
def about(request):
return HttpResponse('about')
Got it to work. This is what was needed:
ALLOWED_HOSTS = ['localhost', '127.0.0.1']
Took me forever to figure this out. :)
There is a little modification is required in your code:
Instead of path('about/', views.about),
write this:
path('about/', views.about,name='about'),
after modify this line , run the server and open this http://127.0.0.1:8000/ URL and add /about and then press enter.
http://127.0.0.1:8000/about
Hope it will work in your case
Can't seem to find anything on this so far, I'm guessing I have something misconfigured somewhere.
I have a pre-existing Django app and am trying to use Wagtail to add a blog in. I have installed as per the instructions and I can access the default landing page so it seems to be installed however I'm stuck with the below error when attempting to access the admin for it and am not sure how to proceed. Guessing its something to do with not defining namespaces somewhere, the Wagtail docs say that its compatible with Django v1.11 but their integration documentation is for Django v2 specifically and is using re_path etc.
'wagtailadmin_api_v1' is not a registered namespace
My main project urls.py
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^blog/', include('blog.urls', namespace='blog')),
url(r'^taggit_autosuggest/', include('taggit_autosuggest.urls')),
url(r'^autocomplete/', include(ac_urls, namespace='ac')),
url(r'^', include('website.urls', namespace='website')),
]
My blog app's urls.py (which is fresh from a "python manage.py startapp blog")
from django.conf.urls import url, include
from wagtail.admin import urls as wagtailadmin_urls
from wagtail.documents import urls as wagtaildocs_urls
from wagtail.core import urls as wagtail_urls
app_name = 'blog'
urlpatterns = [
url(r'^cms/', include(wagtailadmin_urls)),
url(r'^documents/', include(wagtaildocs_urls)),
url(r'', include(wagtail_urls)),
]
When I attempt to access localhost:8000/blog/ I get the default wagtail landing page, if I go to localhost:8000/blog/cms/ I get the above error though. If I go to localhost:8000/blog/documents/ I get a 404 as well.
Not sure where I'm going wrong, have tried using a version of wagtail that still used the Django v1.11 way of routing in urls.py but I got the same error!
Over the weekend I attended a hackathon, at which I created a Django app that ran on 127.0.0.1:8000/myapp/list on my local machine with
python manage.py runserver
Today, I tried to launch another Django app that I had made in the past for bug fixes and things, but when I ran manage.py runserver it keeps redirecting me to 127.0.0.1:8000/myapp/list, even though it's a totally separate app.
Anyone know how to resolve this issue?
urls.py for Django app that I'm trying to run:
from django.conf.urls import url
from TweeTest import views
urlpatterns = [
url(r'^$', views.view_home, name='home'),
url(r'^about/$', views.AboutPageView.as_view()),
url(r'^contact/$', views.ContactPageView.as_view()),
url(r'^result/$', views.view_tweet, name = 'result'),
]
urls.py for Django app I made over the weekend:
from django.conf.urls import include, url
from django.conf import settings
from django.conf.urls.static import static
from django.views.generic import RedirectView
from django.contrib import admin
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^myapp/', include('myproject.myapp.urls')),
url(r'^$', RedirectView.as_view(url='/myapp/list/', permanent=True)),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Is it something to do with the RedirectView line in the second urls.py?
I'm not sure why a totally different Django app is trying to connect to the same URL as the other one... seems strange.
If someone knows the answer to this, that would be greatly appreciated!
Thanks!
UPDATE:
When I try to connect to 127.0.0.1:8000 on incognito mode, it works fine. Could this mean it's a browser issue?
Davis
permanent=True sends a HTTP 301 Permanent redirect to the browser. Browsers tend to cache 301 responses very aggressively, meaning your web browser currently remembers that http://127.0.0.1:8000/ is a permanent redirect to http://127.0.0.1:8000/myapp/list/. Since your browser doesn't know that different Django apps might be running on 127.0.0.1:8000 at different times, it always follows the cached redirect.
You shouldn't use permanent=True unless you know what you are doing. While it can boost the performance on a high-traffic site, it is rarely necessary for low- to medium-traffic sites, and the permanent caching can be a real pain for developers.
Either clear your browser cache, run your Django test server on a different port, or use a different browser.
Have you tried using a different browser or clearing your browser history? This sounds like a browser issue to me.
I am trying to use Authtools for custom users in django.
I am following documentation from their site:
django-authtools.readthedocs
I started a new project, created admin.
Then I:
inserted authtools in INSTALLED_APPS.
inserted AUTH_USER_MODEL = 'authtools.User' in settings.py
in urls i did:
from django.conf.urls import url,include
from django.contrib import admin
from authtools import urls
from django.contrib import admin
from authtools import urls
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^accounts/', include('authtools.urls')),]
Finally I ran python manage.py migrate
and i received following:
django.db.migrations.exceptions.InconsistentMigrationHistory:
Migration admin.0001_initial is applied before its dependency
authtools.0001_initial on database 'default'.
I have no idea what is going on. Does anyone understand?
Thank you.
You need to add authtools to INSTALLED_APPS and set AUTH_USER_MODEL = 'authtools.User' before you do the initial migration.
Since it's a new project, it should be straight forward to drop the database, recreate it, then run migrate again.
I'm looking for a "ready" example of a Login/Register/Authentication system for my site written in Python (so with Django I suppose).
EDIT:
I've tried the Django-registration, see this tutorial
In the tutorials (see STEP 4), I need to update the file urls.py to:
from django.conf.urls.defaults import *
from django.views.generic.simple import direct_to_template
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^admin/(.*)', admin.site.root),
(r'^accounts/', include('registration.urls')),
(r'^$', direct_to_template,
{ 'template': 'index.html' }, 'index'),
)
But when I do this, the Admin page is not available.
When I chance
(r'^admin/(.*)', admin.site.urls)
instead of
(r'^admin/(.*)', admin.site.root)
When I do this, I could login to the Admin page, but I couldn't click on anything...
What am I doing wrong?
https://github.com/ubernostrum/django-registration
This is a user-registration application for Django. There are two registration workflows (one-step, and two-step with activation) built in, and it's designed to be extensible and support building additional workflows.
Try django-registration or Pinax.