(ll_env) C:\learning_log\learning_logs\view.py done ,settings.py done , urls.py done . Starting development server at http://127.0.0.1:8000/
done but http://127.0.0.1:8000/learning_logs
Not Found: /learning_logs
.
.
(ll_env) C:\learning_log\learning_logs\view.py done ,settings.py done , urls.py done . Starting development server at http://127.0.0.1:8000/
done but http://127.0.0.1:8000/learning_logs
Not Found: /learning_logs
.
.
Youâll need to share more details, as itâs impossible to know what the issue could be. Can you share your urls.py
file at the very least?
heu I m new , m i abble to put more than 2 lines ?
here is the files ; views.py
from django.shortcuts import render
# Create your views here.
from django.http import HttpResponse
from django.views import View
# from django.views import views
# ******** 30/11/2023 add from alain *******
class My_View(View): # Correct class definition
def get(self, request, *args, **kwargs):
return HttpResponse("Hello, World!")
urls.py
from django.contrib import admin
from django.urls import path
# ******added by alain 30/11/2023 ******
from django.urls import path
# To this import statement
from learning_logs.views import My_View
urlpatterns = [
path("learning_logs/", My_View.as_view(), name="my_view"),
# path('test/', include('django.contrib.admin.urls')), # Include admin URLs correctly
# path("learning_log/learning_logs/", My_View.as_view(), name="my_view"),
path('admin/', admin.site.urls),
]
settings.py
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'learning_logs' # add by alain
]
The server is running
(ll_env) C:\learning_log>python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
December 02, 2023 - 22:28:10
Django version 4.2.7, using settings 'learning_log.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
From the browser : the admin is working fine , but my view is not found
27.0.0.1:8000/learning_logs
Request Method: | GET |
---|---|
Request URL: | http://127.0.0.1:8000/learning_logs |
Using the URLconf defined in learning_log.urls
, Django tried these URL patterns, in this order:
The current path, learning_logs
, didnât match any of these.
Does http://127.0.0.1:8000/learning_logs/ also not work?
non it does not work ; i have also try to add a test path
path(âtest/â, include(âdjango.contrib.admin.urlsâ)), # Include admin URLs
but this is not working
Side note: When posting code here, enclose the code between lines of three backtick - ` characters. This means youâll have a line of ```, then your code (or template, or error message), then another line of ```. This forces the forum software to keep your code properly formatted.
Iâve taken the liberty of editing your post to correct this, please remember to do this in the future.
Which urls.py file are you showing here? (What directory is it in?)
If itâs not the same file as what your settings.py file is referring to, please post that urls.py file as well.
Hi @ealalin do you have the project on a public repository like Github so I can take a look at the code?
itâs the files that I use for the starting project has requested I will put this into gitub.
I hope that thus answer your question
best regards
No it doesnât. Weâre looking for specifics here. What is your urls setting in your settings.py? What directory is this urls.py file in?
I have add some thing who can help you into github ( where I m not really at home)
but I had trouble to create the sub durectory
Here is the structure :
Directory of C:\learning_log
db.sqlite3
<DIR> learning_log
<DIR> learning_logs
ll_env
manage.py
Directory of C:\learning_log\learning_log
<DIR> .
<DIR> ..
asgi.py
settings.py
urls.py
wsgi.py
__init__.py
<DIR> __pycache__
Directory of C:\learning_log\learning_logs
admin.py
apps.py
<DIR> migrations
models.py
tests.py
views.py
24/11/2023 22:05 0 __init__.py
02/12/2023 20:03 <DIR> __pycache__
The issue is in your urls.py file. You have two definitions for urlpatterns
, and the second overrides the first. (We would have seen this if you had posted the complete urls.py
file above. This is an example of why we often ask to see the complete files, and not just an edited portion.)
Yep, what @KenWhitesell said is exactly correct. Within urls.py
you are defining urlpatterns
twice, once beginning on line 26, and then on line 44, which overrides what you have done on line 26. If you remove lines 44 - 46 you will probably see that it begins working as expected.
@ealalin Supprimer les lignes 44 Ă 46.
thankx for this answers , i m busy now to fit all this to github then , I will correct this , I keep you posted , once again thx
I have corrected my urls
from django.contrib import admin
from django.urls import path
from django.urls import path
from learning_logs.views import My_View
urlpatterns = [
path("learning_log/", My_View.as_view(), name="my_view"),
path('admin/', admin.site.urls),
]
there is a better reaction of the server
but I still have a problem with this part:
from learning_logs.views import My_View
the learning_logs.views is not seen by python !!!
under the directory
Directory of C:\learning_log\learning_logs
I have the file : 02/12/2023 23:57 419 strong text views.py
and in the views.py I have the class My_View(View):
class My_View(View): # Correct class definition
def get(self, request, *args, **kwargs):
return HttpResponse(âHello, World!â)
This is the result of the runserver
Request Method: | GET |
---|---|
Request URL: | http://127.0.0.1:8000/ |
Using the URLconf defined in learning_log.urls
, Django tried these URL patterns, in this order:
The empty path didnât match any of these
The ad work
Toggle theme (current theme: auto)
here are my file
from (ll_env) C:\learning_log\learning_log>
strong texturls.py
from django.contrib import admin
from django.urls import path
from django.urls import path
from learning_logs.views import My_View
urlpatterns = [
path("learning_log/", My_View.as_view(), name="my_view"),
path('admin/', admin.site.urls),
]
from django.shortcuts import render
from the directory :
Directory of C:\learning_log\learning_logs
from django.http import HttpResponse
from django.views import View
class My_View(View): # Correct class definition
def get(self, request, *args, **kwargs):
return HttpResponse(âHello, World!â)
To make your work easier am recreating this environment on gethub.
But I have still probleme with the transfer of these file in it . I 'm not faar from the solution :
@ealalin it doesnât appear that you have a root / home page configured in your urls.py
file, and that is the error you posted. You will only get responses for the /learning_log/
or /admin/
subdirectories, which is why youâre getting a 404 error on /
[quote=âealalin, post:16, topic:25843â]
from django.shortcuts import render
[/quote
I m trying to push the programme to gitub but I have this problem
I have remove the repository from github
ll_env) C:\learning_log>git init
Reinitialized existing Git repository in C:/learning_log/.git/
(ll_env) C:\learning_log>git add .
(ll_env) C:\learning_log>git commit -m âinitial commitâ
On branch main
nothing to commit, working tree clean
ll_env) C:\learning_log>git remote add origin
usage: git remote add []
-f, --fetch fetch the remote branches
--tags import all tags and associated objects when fetching
or do not fetch any tag at all (--no-tags)
-t, --track <branch> branch(es) to track
-m, --master <branch>
master branch
--mirror[=(push|fetch)]
set up remote as a mirror to push to or fetch from
(ll_env) C:\learning_log>git remote add origin GitHub - ealalin/learning_log: Start to learn django
error: remote origin already exists.
(ll_env) C:\learning_log>git remote -v
origin GitHub - ealalin/learning_log: Start to learn django (fetch)
origin GitHub - ealalin/learning_log: Start to learn django (push)
(ll_env) C:\learning_log>git remote set-url origin GitHub - ealalin/learning_log: Start to learn django
(ll_env) C:\learning_log>git remote -v
origin GitHub - ealalin/learning_log: Start to learn django (fetch)
origin GitHub - ealalin/learning_log: Start to learn django (push)
(ll_env) C:\learning_log>git push -u origin main
remote: Permission to ealalin/learning_log.git denied to Ealalin02.
fatal: unable to access âGitHub - ealalin/learning_log: Start to learn djangoâ: The requested URL returned error: 403
why is refusing the access to ealalin02 !!!
i m logged as ealalin01
(ggothreau). I m not sure I understand your comment, and itâs indeed difficult to test it without image , but I work on it .
in my directory : (ll_env) C:\learning_log>cd learning_logs
I have a file admin.py contening the following
from django.contrib import admin
from learning_logs.models import Topic , Entry
#from .models import Topic , Entry
admin.site.register(Topic)
admin.site.register(Entry)
After works directlly with git here is a short resume :
My first attention was to give you a model to be abble to test it directlly in github.
My problem: I was not abble to push it.
My first trial was to generate a ssh key l; load it into github and use a ssh link , the ssh link is working but the push not , here is the solution (simple when you know it)
he error message is indicating that your local branch (main
) is behind the remote branch (origin/main
). This typically happens when changes have been made to the remote branch that you donât have locally. To resolve this issue, you need to integrate the remote changes into your local branch before pushing again.
You can follow these steps:
Fetch the Remote Changes:
git fetch origin
This command fetches the changes from the remote repository, but it doesnât merge them into your working branch.
Merge the Remote Changes into Your Local Branch:
git merge origin/main
if you want to combine steps 2 and 3 into one command, you can use:
bas git
git pull origin main --rebase
C:\learning_log>git fetch origin
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 619 bytes | 38.00 KiB/s, done.
From ssh://github.com/ealalin/learning_log
C:\learning_log>git push -u origin main
To ssh://github.com/ealalin/learning_log.git
! [rejected] main â main (non-fast-forward)
error: failed to push some refs to âssh://github.com/ealalin/learning_log.gitâ
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: âgit pull âŚâ) before pushing again.
hint: See the âNote about fast-forwardsâ in âgit push --helpâ for details.
solution
C:\learning_log>git fetch origin
C:\learning_log>
C:\learning_log**>git rebase origin/main**
Successfully rebased and updated refs/heads/main.
C:\learning_log>
C:\learning_log>git push origin main
Enumerating objects: 9043, done.
Counting objects: 100% (9043/9043), done.
Delta compression using up to 8 threads
Compressing objects: 100% (5770/5770), done.
Writing objects: 100% (9042/9042), 15.71 MiB | 3.07 MiB/s, done.
Total 9042 (delta 2210), reused 9014 (delta 2196), pack-reused 0
remote: Resolving deltas: 100% (2210/2210), done.
To ssh://github.com/ealalin/learning_log.git
879d837âŚ2f2b3eb main â main
Resume of the solution:
Fault still there.
C:\learning_log>git push -u origin main
To ssh://github.com/ealalin/learning_log.git
! [rejected] main â main (non-fast-forward)
error: failed to push some refs to âssh://github.com/ealalin/learning_log.gitâ
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: âgit pull âŚâ) before pushing again.
hint: See the âNote about fast-forwardsâ in âgit push --helpâ for details.
Solution
C:\learning_log>git fetch origin
C:\learning_log>
C:\learning_log>git rebase origin/main
Successfully rebased and updated refs/heads/main.
C:\learning_log>
C:\learning_log>git push origin main
Enumerating objects: 9043, done.
Counting objects: 100% (9043/9043), done.
Delta compression using up to 8 threads
Compressing objects: 100% (5770/5770), done.
Writing objects: 100% (9042/9042), 15.71 MiB | 3.07 MiB/s, done.
Total 9042 (delta 2210), reused 9014 (delta 2196), pack-reused 0
remote: Resolving deltas: 100% (2210/2210), done.
To ssh://github.com/ealalin/learning_log.git
879d837âŚ2f2b3eb main â main
Trial
C:\learning_log>git push -u origin main
Everything up-to-date
Branch âmainâ set up to track remote branch âmainâ from âoriginâ.