Primary prototype / skeleton in Django

Often I create static html prototype/skeletonfor developers with whom I work. This helps to find bugs in the UI / IA and costly rewrites before the site is implemented.

I would like to do it even further and create these prototypes/skeletons in Django. By prototype / skeleton, I mean related static pages that can be easily connected to the end.

I would like to get a few suggestions/ideashow I should customize my templates / links so that they are easy to work with later stages of implementation.

A short list of requirements that come to my mind:

  • Organization of templates, while the entire project will consist of several applications
  • Clear URL Manager and Link Building
  • Ability to display login / logout status
+3
source share
2 answers

I assume that in a more traditional approach, user interface developers and third-party developers work at the two ends of the development spectrum and hopefully converge somewhere in the middle in a gracious manner. If you want your hands to be dirty by writing a few lines of code, you could lay out the entire architecture of the application for developers, because you have the upper part - your problem is with the users, the data they consume and the interactions that they need to perform. This would bring out most of the guesswork for the developers, now only with the need to fill in the holes, connect the dots, or whatever you have.

, , . , . Django, , , , . , , , , , / . , registration, authentication, profiles () . , , , , , , . , , , , , . - , , - , , , (models.py, views.py, test.py) , , , . , .

. Django - URL- . . URL- , , .

. URL- , , , authentication:login, authentication:logout, registration:register, registration:confirm, registration:activate .. , , . URL authentication:login, , , , , , , - .

, :

  • , , , .
  • core, , /.
  • /core/templates/core/base.html, CSS/JS, , , ( ) , , , . "One Template To Rule Them All", , / .
  • /core/temaplates/core/welcome.html, "Hello world!". .
  • /core/urls.py :

    from django.conf.urls.defaults import *
    from django.views.generic import TemplateView  
    
    
    urlpatterns = patterns('',
    
        # Welcome
        url(
            r'^$', TemplateView.as_view(template_name='core/welcome.html'),
            name='welcome'
        ),
    
    )
    
  • /urls.py:

    from django.conf.urls.defaults import *
    from django.contrib import admin
    
    
    admin.autodiscover()
    
    urlpatterns = patterns('',
        url(ur'^', include('core.urls', namespace='core')),
        url(ur'^admin/doc/', include('django.contrib.admindocs.urls')),
        url(ur'^admin/', include(admin.site.urls)),
    )
    
  • http://localhost:8080/, . "Hello World!", .

  • : , , , , urlconf.

. , /urls.py , , . /core/urls.py :

from django.conf.urls.defaults import *
from core import views


urlpatterns = patterns('',

    # Welcome
    url(
        r'^$', views.Welcome.as_view(),
        name='welcome'
    ),

)

/core/views.py :

from django.core.views.generic import TemplateView

class WelcomeView(TemplateView):

    template_name='core/welcome.html'

    extra_context={
        'page_title': 'Welcome!',
        'page_keywords': 'relevant,page,keywords',
        'page_description': 'Something equally relevant',
    }

    def get_context_data(self, **kwargs):
        context = super(WelcomeView, self).get_context_data(**kwargs)

        context.update(self.extra_context)
        return context

, ! , , . , . - , , , , - .

, , , , , , . , , , . , , , , , , , .

+9

, Django. direct_to_template , , . , , .

, , URL- . , URL- . .

, , / , .

+6

Source: https://habr.com/ru/post/1794600/


All Articles