
from flask import Flask, url_for

app = Flask("flaskrst")

@app.context_processor
def inject_navigation():
    navigation = []
    for item in app.config.get('NAVIGATION', []):
        kwargs = item.copy()
        del kwargs['route']
        del kwargs['name']
        
        link = url_for(item['route'], **kwargs)
        navigation.append((link, item['name']))
        
    return dict(navigation=navigation)

from flask import Flask, url_for

app = Flask("flaskrst")

@app.context_processor
def inject_navigation():
    navigation = []
    for item in app.config.get('NAVIGATION', []):
        if item.has_key('route') and item.has_key('label'):
            kwargs = item.copy()
            del kwargs['route']
            del kwargs['label']
        
            link = url_for(item['route'], **kwargs)
            navigation.append((link, item['label']))
        elif item.has_key('url') and item.has_key('label'):
            navigation.append((item['url'], item['label']))

    return dict(navigation=navigation)
Rename navigation config key name to label and add support for links to external sites over the url key name
Rename navigation config key name to label and add support for links to external sites over the url key name

  
  from flask import Flask, url_for
  
  app = Flask("flaskrst")
  
  @app.context_processor
  def inject_navigation():
      navigation = []
      for item in app.config.get('NAVIGATION', []):
+         if item.has_key('route') and item.has_key('label'):
-         kwargs = item.copy()
+             kwargs = item.copy()
-         del kwargs['route']
+             del kwargs['route']
-         del kwargs['name']
+             del kwargs['label']
          
-         link = url_for(item['route'], **kwargs)
+             link = url_for(item['route'], **kwargs)
-         navigation.append((link, item['name']))
+             navigation.append((link, item['label']))
-         
+         elif item.has_key('url') and item.has_key('label'):
+             navigation.append((item['url'], item['label']))
+ 
      return dict(navigation=navigation)
Rename navigation config key name to label and add support for links to external sites over the url key name
## Code Before:

from flask import Flask, url_for

app = Flask("flaskrst")

@app.context_processor
def inject_navigation():
    navigation = []
    for item in app.config.get('NAVIGATION', []):
        kwargs = item.copy()
        del kwargs['route']
        del kwargs['name']
        
        link = url_for(item['route'], **kwargs)
        navigation.append((link, item['name']))
        
    return dict(navigation=navigation)
## Instruction:
Rename navigation config key name to label and add support for links to external sites over the url key name
## Code After:

from flask import Flask, url_for

app = Flask("flaskrst")

@app.context_processor
def inject_navigation():
    navigation = []
    for item in app.config.get('NAVIGATION', []):
        if item.has_key('route') and item.has_key('label'):
            kwargs = item.copy()
            del kwargs['route']
            del kwargs['label']
        
            link = url_for(item['route'], **kwargs)
            navigation.append((link, item['label']))
        elif item.has_key('url') and item.has_key('label'):
            navigation.append((item['url'], item['label']))

    return dict(navigation=navigation)