OpenedX url referencing - python

I am experimenting with adding an anchor tag in the file "course_outline.html" in the template folder of cms. I want the user to be redirected to another page on clicking this. For experimentation I am doing <a href="<% url upload_transcripts %>".. >.( Note that upload_transcripts is already defined in urls.py in the cms folder as url(r'^transcripts/upload$', 'contentstore.views.upload_transcripts', name='upload_transcripts')
)
This is giving an error. In particular the error page saying 'The studio servers encountered an error' and nothing else. Note that I have already tried <a href="{% url upload_transcripts %}" .. > with no success . Can someone help with this ?
Environment: Devstack version in Ubuntu 12.04

open-edx is using mako templating its syntax is diffrent from jinja templating , the error occured to you will be a syntax error.
You can use reverse function in django urlresolvers
try this
${_('Redirect')}.
dont forget to import it in your html
from django.core.urlresolvers import reverse

I ended up created a new views.py and editing the urls.py. This seems to have solved my problem.

Related

Page not found error in django where it is not supposed to rise

I am building a video player app in django. But, when going to the register route, I get this error:
Page not found (404)
Request Method: GET
Request URL: http://localhost:8000/users/login/%7B%25%20url%20'register'%20%7D
I don't even have a url called users/login/register. And I have checked my urls.py. Here it is:
urlpatterns = [
path('register/',views.register,name='register'),
]
And here is the link that leads to this route:
Register
I have built many apps with django but have never encountered an error like this. Why am I getting this error?
You are missing a % in your a tag, it should be
Register
Does this solve your problem?
probably, url is not recognized because of absence "%" before brace in the last line.
Register

Django Admin Look strange

It's a new install of Django 3 and I get this admin look for the panel :
I have no error in the browser console
I have already done
python3 manage.py collectstatic
One clue :
To be able to see this admin panel without apache 500 error, i must comment :
django.contrib.staticfiles
in settings.py, under MIDDLEWARE
if django.contrib.staticfiles is called in MIDDLEWARE, I have this apache error :
TypeError: 'module' object is not callable,
My css and js looks ok...
I can't find how to correct this view
from django.contrib import admin
admin.autodiscover()
admin.site.enable_nav_sidebar = False
Add the above code somewhere in your main urls.py file
This issue has been raising in django 3.1.
It's not an error. It's just a new side bar being added therein.
Add the above code to disable it.

Django how urls.py how to add url / problem in adding url

i created my first app in Django. and when i am running it in my chrome browser using the url
http://127.0.0.1:8000/hello
It didn't open but when i used the url:-
http://127.0.0.1:8000/
It worked, don't know why. I added the url in urls.py file. like this.
path('hello', views.hello_world_view, name='hello')
suggest me where i am going wrong.
Thanks
URL patterns require a trailing slash in order to work
path('hello/', views.hello_world_view, name='hello')
Write like this
path('hello/', views.hello_world_view, name='hello')
read this djangoproject for URLs dispatcher it will help you how to configure URL into Django

Page not found on Django - Empty paths

I'm trying to run this library. I downloaded and copied it on my desktop, then i tried to run it using:
py -3.7 manage.py runserver
I got:
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
But when i go to that url i keep getting this error:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/
Using the URLconf defined in django_google_authenticator.urls, Django tried these URL patterns, in this order:
^admin/login/$
^admin/
The empty path didn't match any of these.
I don't understand what's wrong, can someone help me? Thanks in advance!
I think thats the normal behavour of Django, as you can see it is saying that your path didn't match any of the configured ones, like admin, so why don't you try http://127.0.0.1:8000/admin/to access Django Admin login page.
If you want to see something different from a 404 with the base url you need to configure your urls and maybe add a redirect view, in that way when the base url is use it will redirect to your admin or other preferred page.

django flatpages vs. named url's reverse

I am trying to set up flatpages for my django project. everything works fine. except this guy:
I have urls like:
url(r'^terms/$', TemplateView.as_view(template_name='terms.html'),
name='terms'),
which goes to a static html file. and in template i have:
terms
now I set up a new flatpage for terms page. Now I want to break the old static url terms (so that 404 get raised) so that my new flatpage will be found. my flatpages slug is also /terms/.
How can I "remove" the old slug so that my flatpage will be called?
.. i mean, without changing {% url 'terms '%}
You can specify the url to a single flatpage in your urls.py. In your case, all you need is:
url(r'^terms/$', 'django.contrib.flatpages.views.flatpage', {'url': '/terms/'}, name='terms')
See: https://docs.djangoproject.com/en/dev/ref/contrib/flatpages/#using-the-urlconf

Categories

Resources