I have a small problem with URLs file in Django,
I'm trying to connect between app URLs, review, and the main urls
I have
python 3.9.1
Django 3.2.0
I have been searching and try many things on StackOverflow but still, I don't find why the server doesn't work just when I put this line with a red arrow on the comment,
please help!!
One typo I can see is in signup/urls.py-
Change URLPattern to urlpatterns. Let me know if that fixes the issue in the comment?
In your signup folder's urls.py file replace URLPattern to urlpatterns.
Try:
urlpatterns = [
...
]
Happy coding :)
Related
The question may have been asked many times, but I couldn't find something about this which is a basic stuff to do. I have a problem with my website one of the sub urls of google search redirects to the wrong page.
Here are the urls :
www.example.com/login/user/ #wrong url
www.example.com/accounts/login/ #correct url
urls.py : url(r'^accounts/login/$', auth_views.login, name='login'),
I'd like the user to be redirected to the correct url if he access the wrong one. I know that it is possible to do that with views using redirect(reverse('...')) but doing it just for this purpose doesn't sound like the best way.
Is there a way to redirect an user when he enters a wrong url to another one only by using urls.py ?
You would normally do this on your webserver, e.g. Apache
RewriteRule /login/user/ /accounts/login/ [R=301,L]
That way you don't need to load Django to do a static redirect (you might build up a longer list of these as site-designs evolve).
One solution is to use the RedirectView inside urls.py as shown here in the docs
So, for example:
url(r'^login/user$', RedirectView.as_view(pattern_name='login')),
To urls.py, you can add:
url(r'^login/user/$', auth_views.login, name='login')
It seems like you are aware of that. Did I not understand your question?
I am looking to use the Django-Scheduler package in my Django project but am finding it difficult to understand how to actually implement the calendar so that it can be seen on the actual website. My website is meant to be a timetable scheduling system where users can login and use and edit there own timetable/calendar. I have already implemented the login and registrastion using django registration redux. I have also already installed django-scheduler using pip and have edited my projects settings like so:
INSTALLED_APPS += ('schedule',)
add to
TEMPLATE_CONTEXT_PROCESSORS += (
"django.core.context_processors.request",
)
This is explained on the github page for django-scheduler. I have read through the documentation but am still not sure as to how to have a usable calendar on the page the user is sent to after logging in.
Could someone please explain to me as to how I can achieve this. What do I put in my projects url.py file for django-scheduler like eg the url for django-calendarium,
url(r'^calendar/', include('calendarium.urls')),
Do I have to create new templates etc.
Hope somebody can help ! Thanks
this will serve you
url(r'^calendar/', include('schedule.urls')),
if you still to know more about the url, views, models and config of schedule check https://github.com/llazzaro/django-scheduler/tree/develop/schedule and https://github.com/llazzaro/django-scheduler/tree/develop/schedule/urls.py for
I installed Django and enabled the admin site. When I go to the admin page, I get the following
The image does not look the official Django tutorial. In settings.py I updated TEMPLATE_DIRS with the correct path.
TEMPLATE_DIRS = (
"/var/www/mysite/templates/admin"
)
I also tried restarting Apache many times. Any suggestions on what I might be doing wrong? Thank you.
It's an issued related to static files rather than templates:
https://docs.djangoproject.com/en/dev/howto/static-files/#serving-static-files-in-production
Use the developer tools on your browser to looks at what requests are being made. Most likely some static files like CSS, etc. are not being served up.
I am using Lighttpd and Django. I have configured my Lighttpd server to pass all the requests ending with ".psp" extension to Django.
My startup page is a page served through Django, which is accessed as "http://192.168.1.198/home.psp". I want to enable the user to browse this page without writing "home.psp" explicitly in the url i.e. using "http://192.168.1.198"
Is this possible?
Thanks for any help in advance.
I think you're confusing concepts here between the "old" method of having individual files represent web pages which themselves contain code that is passed off to an interpreter before being sent in a response to how django/frameworks work.
If you're familiar with apache, imagine django as in part taking on the role of mod_rewrite. Django, and other frameworks, have what's called a dispatcher, or routing, mechanism.
Basically, they subscribe to the MVC pattern that says you should separate out the model, controller and view (in django parlance, model, template and view).
Now what then happens is you have a file called urls.py in django, which contains a list of routes (urls) and names of methods (usually contained in views.py) which handle them. Here's an example:
urlpatterns = patterns('',
url(r'^dologin$', 'testapp.views.auth_login', name="auth-login-uri"),
url(r'^doopenidlogin$', 'testapp.views.auth_openid_login', name="auth-openid-login-uri"),
url(r'^dologout$', 'testapp.views.auth_logout', name="auth-logout-uri"),
url(r'^login$', 'testapp.views.loginform', name="login-form"),
url(r'^openidlogin$', 'testapp.views.openidloginform', name="openid-login-form"),
url(r'^$', 'testapp.views.index', name="index"),
)
Here testapp is a python package, views.py is a python file and index is a django view. The url is constructed from regex, so I can have whatever I want as the url, much how stackoverflow urls are formed.
So basically, you never need file extensions again. I'd strongly suggest getting a good book on django - there are a few around.
What you might be looking for is the index-file.names directive in Lighty's configuration file. Just add "home.psp" to the list in your configuration file, and Lighty will look for it when no filename is specified.
I solved the problem myself. Here is what I did:
I had to add a statement inside url.rewrite-once block of lighttpd's configuration file like:
url.rewrite-once = (
"^(/media.*)$" => "$1",
"^(/static.*)$" => "$1",
"^/favicon\.ico$" => "/media/favicon.ico",
"^(/)$" => "/my_project_dir/home.psp",
"^(/.*)$" => "/my_project_dir$1",
)
Apart from this, I added the following line in my urls.py:
(r'^$',my_index_view_name),
Hope this helps someone in the future. Thanks everybody for your replies above. Cheers!
EDIT: Issue solved, answered it below. Lame error. Blah
So I upgraded to Django 1.1 and for the life of me I can't figure out what I'm missing. Here is my traceback:
http://dpaste.com/37391/ - This happens on any page I try to go to.
I've modified my urls.py to include the admin in the new method:
from django.contrib import admin
admin.autodiscover()
.... urlpatterns declaration
(r'^admin/', include(admin.site.urls)),
I've tried fidgeting with paths and the like but nothing fixes my problem and I can't figure it out.
Has something major changed since Django 1.1 alpha -> Django 1.1 beta that I am missing? Apart from the admin I can't see what else is new. Are urls still stored in a urls.py within each app?
Thanks for the help in advance, this is beyond frustrating.
I figured it out. I was missing a urls.py that I referenced (for some reason, SVN said it was in the repo but it never was fetched on an update) and it simply said could not find urls (with no reference to notes.urls which WAS missing) so it got very confusing.
Either way, fixed -- Awesome!
try this:
(r'^admin/(.*)', admin.site.root),
More info
What is the value of your ROOT_URLCONF in your settings.py file? Is the file named by that setting on your python path?
Are you using the development server or what?