I have installed django-page-cms successfully i think. Like other cms, it is also for creating new pages. But I already have html pages in my project. How to integrate with that?
They want me to put place holder in html page, like:
{% load pages_tags %}
but I think this will bring the content from the already created page in admin
Can anyone tell me how to integrate with my existing pages?
First you need to create page in admin console. Then add the placeholder in your template
like what tutorial saying
{% get_page "news" as news_page %}
{% for new in news_page.get_children %}
<li>
{{ new.publication_date }}
{% show_content new body %}
{% endfor %}
Related
I am making my own portfolio website using Django.. So the idea is: Make posts containing websites that i've developed. All these posts will be displayed in a page called "Projects" and then you can access a single project to read about it. Every project i upload have an ID, so i used this code to acess each project page:
# Single project page
path('projects/<int:post_id>/', views.project, name='project'),
Then in my PROJECTS page i have a simple(for now) HTML code to show all my projects and link them to the single project page. What i want to know is how to LINK this ID generated URL in this code:
<ul>
{% for project in projects %}
<li>{{ project }}</li>
{% empty %}
<li>No project have been added yet.</li>
{% endfor %}
</ul>
I tried using:
<li><a href="{% url 'main_portfolio/projects/<int:post_id>/' %}</a></li
And some other things but nothing i try is working.
Maybe try <a href="{{ project.get_absolute_url }}">, or
<a href="projects/{{ project.id }}/">
You can work with the {% url … %} template tag [Django-doc]:
<li>some text</li>
I have a form I'm working with in Django.
I have a built in error message I'm trying to get to render on the form.
My first step is to get the error message to render on the form and then I will go into the function and tweak when it shows up.
My problem emerges when it comes to doing it in python.
Normally, my preferred way would be to JQuery for the footer and use JavaScript to append/prepend the HTML. Then set it to show/hide based on conditionals.
However, for this I am wanting to do it in Python to make it easier for the people working w/ me.
Here's an example of the error message HTML I would like to use for appending to something else in JS.
error_field.append('<em for="name" class="form-error-message text-danger">');
Here is an example of the Django Code Block I would like to add it within
{% block form-footer %}
{{ block.super }}
{% endblock %}
What is the easiest way to accomplish this within Python/Django? To be clear, I can figure out the conditional stuff myself. Just the rendering of the specific HTML/CSS error class I have already created. I should be able to do the conditional/function part of this myself.
I can just show you an example, this is a part of my project
views.py
try:
user=User.objects.get(username=username)
except:
messages.info(request,'username does not exist')
return redirect('login')
return render(request,'users/login-register.html')
html
{% if messages %}
{% for i in messages %}
<div class="alert alert--{{i.tags}}">
<p class="alert__message">{{i}}</p>
<button class="alert__close">x</button>
</div>
{% endfor %}
{% endif %}
You can use this anywhere in your html page. This is a common page, and everything in here is extended. And of course this is an example similar to your problem. Check it out if you want
I am looking for some kind of example with flask using a required form on the home page of my site that requires the user to select an option before being allowed onto the rest of the site. The form is used for selecting a collection out of my mongo db database. I need to know what collection the user wants to use before going anywhere else on the site. Once this done I need to make sure I can use this information on my other route and views on my site.
What you want is to implement a login infrastructure.
using flask, you have a base template, where every other template is extending, what you can do is something like the following:
base.html:
{% if current_user.is_authenticated %}
<content>
{% block content %}
{% endblock %}
</content>
{% else %}
<login-form>
{% block content %}
{% endblock %}
</login-form>
{% endif %}
using this code, the content is shown only and only if the user is authenticated. in login-form HTML you should have a form to ask the credentials needed to authenticate the user and then allow them access to rest of the site.
in other template files, you continue to use the same practice:
dashboard.html:
{% extends 'base.html' %}
{% block content %}
<YOUR HTML CONTENT>
{% endblock %}
the content of dashboard.html is only shown to the user, if they are logged in(current_user.is_authenticated = True)
this is because dashboard.html is shown inside the content block of base.html witch is only shown or rendered if that condition is met.
you can use anything else instead of is_authenticated like the collection being selected or anything like that. the procedure to do it is the same.
So I am new to Django (and complete the 7 part tutorial) as well as read the flatpages app documentation.
At the end of which, whoever wrote the Django documentation gives a demonstration as to how one would retrieve all the flatpages:
{% load flatpages %}
{% get_flatpages as flatpages %}
<ul>
{% for page in flatpages %}
<li>{{ page.title }}</li>
{% endfor %}
</ul>
I now have flatpages working (e.g. if I go to /pages/my_flatpage/ the default template I have renders. as I have included url(r'^pages/', include('django.contrib.flatpages.urls')) in the urlpatterns.
So I am now in another app of mine and want to link to these flatpages. Using the code above I create the links. However, when I click on them, they do not render as they are routed to /my_flatpage/ rather than /pages/my_flatpage/.
So I tried including the url pattern in my app, but that didnt work. How can I get the to go to the right place?
Since you're not hosting the pages directly at the root, the url attribute doesn't return the whole path. Instead you should use the URL reversing functionality as with any other object:
{% for page in flatpages %}
<li>{{ page.title }}</li>
{% endfor %}
I'm a beginner in django-oscar and I try to manage a new view on the page.
I've already created two pages with django-oscar dashboard,
https://ibb.co/cM9r0v
and made new buttons in the templates:
Lib/site-packages/oscar/templates/oscar/partials/nav_primary.html
https://gist.github.com/Kalinar/076fc8144869c3b50fc0bc9e52f825e4
I have no idea how to make a good a href="???" to new pages in buttons ... can someone help?
Maybe there is better way to do it, can you explain it to me?
Oscar uses Django's flatpages app, so you can use their template tags to dynamically add in navigation links to the pages you create.
{% load flatpages %}
{% get_flatpages as flatpages %}
{% for page in flatpages %}
<li class="dropdown active">
<a href="{{ page.url }}" class="dropdown-toggle" {% if not expand_dropdown %} data-toggle="dropdown"{% endif %}>
{% trans page.title %}
</a>
</li>
{% endfor %}
You can find more information on the flatpages app in the Django flatpage documentation.
You already know the title and of course the id of the page, and each page is an instance of the model PagePromotion, just query the model for such name/id and use the attribute page_url of the returned instance to send it within a variable in the context of the view that renders the menu.
Then in the template:
href="{{ variable_containing_url }}"