Reputation: 31
I have seen several questions relating to this topic but none work for me I am running Django 3 and python 3 with ubuntu and using firefox browser
when i run "python3 manage.py runserver"
my homepage loads at 127.0.0.1:8000 but when I add /admin in the browser
127.0.0.1:8000/admin
it still stays at the homepage not the admin page
i notice on the running server i get
December 09, 2019 - 00:40:46 Django version 1.11.11, using settings 'mysite.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C. " "and when i add /admin the following line appears"
[09/Dec/2019 00:46:05] "GET /admin HTTP/1.1" 200 3
but still i dont see the admin page
please ask and i can share
"settings.py" etc and any other information update
my "main" folder has a urls.py file which looks like:
from django.conf.urls import url
from . import views
app_name = "main"
urlpatterns = [
url(r'^', views.homepage, name="homepage"),
]
my "mysite/mysite" folder has a urls.py file that looks like:
from django.conf.urls import url, include
from django.contrib import admin
urlpatterns = [
url(r'^', include('main.urls')),
url(r'^admin/', admin.site.urls),
]
Thanks to a comment from @chrisbyte if i comment out
#url(r'^', include('main.urls'))
Line then my admin page shows up, But then I dont get anything I have done on my "main" page.
Upvotes: 0
Views: 446
Reputation: 31
The main problem was that due to the fact I was not working in an environment that had python 3 as its main python, it had actually downloaded an earlier version of Django. this was more confusing as my "IDLE" pointed to python 3, and when i asked for Django version In Idle it told me version 3, but when i asked for Django version in a shell in my workspace it told me the actual version was 1.
I had tried to adapt a tutorial that used "Path" syntax to my code above which did not exist in the earlier version of Django.
I followed another tutorial that was for an earlier version of django and it worked ok.
The lesson learned was to use a conda environment with the correct version of python.
Upvotes: 0
Reputation: 1633
So with formatting, your urls.py looks something like this?
from django.conf.urls import url, include
from django.contrib import admin
urlpatterns = [
url(r'^', include('main.urls')),
url(r'^admin/', admin.site.urls),
]
What happens if you put the admin
url route before the main.urls
route, like this?
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^', include('main.urls')),
]
I believe the admin
portion should come first so it is not overwritten by main.urls
Upvotes: 1