웹 포털을 만드는 중입니다. 프로필/대시 보드 변경 배경을 변경하는 기능을 사용자에게 제공하고 싶습니다. 아무에게도 이것을 달성하기위한 효율적인 접근 방법을 안내해 줄 수 있습니까? 감사합니다Django : Customizable templates
3
A
답변
2
이것은 django 템플릿보다 css 및 javascript와 더 많은 트릭입니다.
여기 장고와 관련된 유일한 점은 이러한 환경 설정을 실제로 저장하는 것입니다.
실제 배경 이미지의 파일 경로. 당신은 모든 사용자에 대해 서로 다른 디렉토리를해야 할 이유가 표시되지 않습니다
how to change html background dynamically
편집
:
그 후에 당신은이 답변에 설명 된 것과 유사한 일을 할 것입니다. 장고 템플릿 당신이 원하는 것을 할 수있는 충분한 능력을 제공합니다.
예를 들어 각 사용자가 자신의 배경 그림을 업로드 할 수 있다고 가정 해 봅니다. 또한 사용자에 대한 추가 정보 인 을 저장하는 데이 인기있는 장고 패턴을 따르는 것으로 가정합니다.
class UserProfile(models.Model):
CHOICES = (
('vertical', 'Vertical'),
('horizontal', 'Horizontal'),
)
user = models.OneToOneField(User)
background_image = models.ImageField(upload_to='images')
dashboard_layout = models.CharField(max_length=10, choices=CHOICES)
당신은 (중 아약스 유무에 관계없이) 자바 스크립트 문맥이 추가 정보를 전달하고 모든 개별 사용자에 대한 배경 이미지를 변경할 수 있습니다
https://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users 그래서 우리는이 UserProfile
모델을 가지고있다.
는 또한 우리는이 같은 템플릿 수준에서 특별한 레이아웃을 할 수있는 :
{% extends "base.html" %}
{% block main_body %}
{% if request.user.get_profile.dashboard_layout == 'vertical' %}
{% include "layouts/vertical.html" %}
{% else %}
{% include "layouts/horizontal.html" %}
{% endif %}
{% endblock main_body %}
관련 문제
- 1. django templates : include 및 extend
- 2. jQuery Customizable tabbing plugin?
- 3. Symfony Templates within Templates
- 4. django templates - 같은 폴더에있는 다른 블록을 포함합니다.
- 5. django-templates/django-forms에 이미지/배경 이미지 표시
- 6. Templates - Exercises
- 7. CodeIgniter templates
- 8. asp.net - templates
- 9. Photoshop Templates
- 10. Sharepoint MasterPages/Templates customization
- 11. Joomla Mobi Templates
- 12. xsl apply-templates 문제
- 13. Generics/templates in python?
- 14. Aptana Javascript templates
- 15. `apply-templates` matching 이해하기
- 16. jquery templates selection
- 17. Jquery Templates 성능
- 18. MediaWiki : Dynamic Templates (infobox)
- 19. Symfony SonataAdmin Templates
- 20. Variadic Templates with MSVC
- 21. VS2008 extern templates
- 22. Google Maps Bubble Templates
- 23. perl/sqlite cgi templates
- 24. Haml Inherit Templates
- 25. PSD to SharePoint Templates
- 26. MonoGame Mac Templates 설치
- 27. Velocity Templates Path outside JBoss
- 28. boost icl interval_map interval_set templates
- 29. C++ templates 클래스와의 부분 전문화
- 30. MVC 3 개의 DisplayFor-Templates
내가 (기본 템플릿에서 복사) DIFF 디렉토리를 생성하고 사용자에게 할당 같은 것을 생각하고 사용자 있도록 특정 템플릿은 백엔드에서 표시됩니다. 하지만 이렇게하면 서버로드가 증가하고 리소스가 소모됩니다. 더 효율적인 것은 인정 될 것이다. –
@TarunGaba가 내 대답을 업데이트했습니다. 나는 그것이 당신의 질문에 더 명확하게 응답하기를 바랍니다. – rantanplan