I've been doing a lesson on udemy trying to make a clone site of producthunt using django. I've tried asking there, but I don't get an answer. For some reason when I run the exact same code as the instructor, I get an error when trying to load the page localhost:8000/signup or any other pages other than the home page.
I get this error:
error
Settings file:
settings
Main urls:
main urls
app urls (named accounts):
app urls
views:
app views
finally my file structure for reference:
directory
I've been trying to figure it out with no avail. Any help would be great thank you.
signup is a route in the accounts app. In your main urls.py you include your accounts.urls under accounts/. Putting that all together, with your current structure you should be hitting accounts/signup rather than just signup.
There's no url /signup in your web.
You're url is for accounts/signup/
Related
I am following an online course on Django, and my browser fails to load the admin page. I created a job, added it to INSTALLED_APPS in settings.py, and added it in admin.py as follows:
from .models import Job
# Register your models here.
admin.site.register(Job)
In urls.py I believe I have the standard admin url
urlpatterns = [
path('admin/', admin.site.urls),
path('home/', jobs.views.home, name='home'),
]
I'm not sure if any other any information is needed but please ask if there is anything else. I start the server using python manage.py runserver and it can access /home okay, but if I change the url to admin or admin/ it says 'Firefox can’t establish a connection to the server at 127.0.0.1:8000.'.I've tried it on different browsers and the same outcome is reached. My question is similar to the one here: Django error browser is unable to connect at 127.0.0.1:8000/products/ and I tried all of the solutions there but none worked. I followed the tutorial very specifically, so I have no idea what is causing this. I am using Atom on a Windows 10 machine, the project is connected to a postgresql database.
UPDATE/EDIT 08/23/20 10:31AM PST.
Here is a screenshot of INSTALLED_APPS:
There is no error in console when I try to open admin. If I run the server as shown below and open the link http://127.0.0.1:8000/admin, the server just stops working and my command line returns to just taking in commands. Details in screenshot below.
UPDATE/EDIT 08/23/20 12:07PM PST.
I recently worked on a project that had an app named 'catalog'. While I was working on it, I changed the URLconf so that the root URL could be redirected to the app.
I wrote the below code to do this:
# within the project's URLconf file
from django.views.generic import RedirectView
urlpatterns += [
url(r'^$', RedirectView.as_view(url='/catalog/', permanent=True)),
]
I was working on the local development server, and the root URL (127.0.0.1:8000) was successfully redirected to the 'catalog' app (127.0.0.1:8000/catalog/).
However, when I created a new project, the root URL of this NEW project ALSO tried to redirect to the 'catalog' app of the previous project.
So where as I should be seeing the "it worked!" page at the root URL for the new project, I am instead redirected to the 'catalog' app's URL of the previous project, where the 404 page is displayed (obviously, because the 'catalog' app is not part of the new project).
Instead of this:
It Worked Page
Seeing this:
404 Page
It seems to me that the settings from the previous project have somehow affected the local server permanently so that the modified URLconf setting is carried on to any subsequent projects.
I could not find exactly what was causing this issue so I just ran the new project on a different port (8001) using the
python manage.py runserver 8001
command, and this seemed to fix the issue. However, I regard this only as a temporary workaround and I want to find out the root cause of the issue.
If I can't fix it, I would like to "reset" the default port (8000) so everything goes back to default settings.
Is there a way to completely "reset" either the local server or django itself so that all the settings go back to how they were released?
I am working on a project that uses Django and Angular. I do not have a background as a web developer so please try to explain your answer so that a novice person can understand it.
Basically I want to make it so that the login page is the default page instead of the index page.
I currently have the following url handler in my main Django project urls.py:
url(r'^$', 'core.views.generic.index')
I also have another urls.py in an app called core that sends visitors to the login page:
url(r'^/login$', private.MeLogin.as_view())
Now I want the login page to become the default page instead if the index page. How can I do that?
I have tried adding the following the the views file in the core app:
#login_required(redirect_field_name='', login_url='#/login')
def index(request):
return render_to_response('html/index.html', locals(), context_instance=RequestContext(request))
Unfortunately I get the message
This webpage has a redirect loop
I do not know how to solve this problem. Basically I want users to be redirected to the login page if they enter any URL that is not handled by other URL handlers. When they successfully log in they are redirected to a dashboard page automatically.
EDIT:
The login page URL is handled in the core urls.py file and points to a different view than index.
url(r'^/login$', private.MeLogin.as_view())
Web servers, in this case Django, do not see the fragment after the #. You are redirecting from / to /, creating a redirect loop.
If you want to redirect to the Django login url, you need login_url='/login'.
As an aside, you should remove the leading slash from your regex r'^/login$.
In #login_required(redirect_field_name='', login_url='#/login')
remove redirect_field_name='', it really is not neccessary and make sure that #/login in login_url='#/login is the same as in your url.py file:
like
views.py
#login_required(redirect_field_name='', login_url='accounts/login/')
as
url.py
url(r'^accounts/login/', auth_views.login),
I assume your Angular & Django apps are running in two seperate ports, like:
Django on port 8000
Angular on port 1000
So if you give /#/login it will redirect for the same with Django port (8000/#/login).
So why don't you give the full URL www.example.com/#/login?
Normaly django looks for a url in url.py file...
if it finds it load the relevent HTML page and if it doesn't find it shows:
Page not found (404) with the msg:
You're seeing this error because you have DEBUG = True in your Django
settings file. Change that to False, and Django will display a
standard 404 page.
I want to change standard 404 page that django shows. I have a HTML page that I created PageNotFound.html I want django to show everytime there is a Page not found (404) when DEBUG = False. How do I do that?
In order to show customized HTML when Django returns a 404, you can create an HTML template named 404.html and place it in the top level of your template tree. This template will then be served when DEBUG is set to False.
https://docs.djangoproject.com/en/dev/topics/http/views/#the-404-page-not-found-view
Also, there is an useful section "Customizing error views".
And in the case you want to test your template withour turning DEBUG=False, you can run manage.py runserver --insecure.
It will force Django to serving static files with the staticfiles app even if the DEBUG setting is False. But note that it it only for local development and could be insecure. You can read more about this option here.
Here is a quote from the Django doc:
This template should be called 404.html and located in the top level of your template tree.
Check here for the full text; for non 1.8 doc it should be somewhere around here: Writing views > Returning errors > The Http404 exception.
You should create following view:
def custom404(request):
return render(request, '404.html', status=404)
And connect it with following construction in urls.py:
handler404 = 'path.to.views.custom404'
I trying to add to my project django log object to my django project
I followed these steps
1)pip install django-object-log
2)copied the object_log folder into your Django project.
3)Add "object_log" to INSTALLED_APPS
4)Run ./manage.py syncdb
5)add this url to my project urls ....url(r'yasmina', include('object_log.urls')),
But i don't know what to do next so any help plz ??
and this is one of the urls in url.py of the django object log ...url(r'^user/(?P\d+)/actions/?$', 'list_user_actions', name="user-object_log-actions"),
when i runned the server and added this url to my browser http://localhost:8000/yasmina/user/2/actions/
I got error this url doesnt match
Looks like your Url pattern matches
http://localhost:8000/user/2/actions/.